Skip to content

Inaccurate/Unhelpful MockFileSystem UNC path error message on Unix-like systems #1350

Description

@HarrisonTCodes

Issue

When creating a MockFileSystem with initial files using UNC paths (Windows format) on Unix-like systems, the error handling can be contradictory to the code and inaccurate, as the error message is fixed/hardcoded to Windows paths. For example, when running the below on a Unix-like system

varfilesystem=newMockFileSystem(newDictionary<string,MockFileData>{{@"\\server\share\file","content"}});

The error reads System.ArgumentException: The UNC path should be of the form \\server\share. (Parameter 'path'), despite the path being in that exact form, and actually requiring the form //server/share on Unix-like systems.

Cause

It seems there is handling of UNC paths with forward-slash separation following this standard in the MockFileSystem class, from this line:

varisUnc=StringOperations.StartsWith(fixedPath,@"\\")||StringOperations.StartsWith(fixedPath,@"//");

The next line uses the platform-specific separator:

lastIndex=StringOperations.IndexOf(fixedPath,separator,2)

Which will then lead to errors if trying to use backslash-separated UNC paths on Unix-like systems, or presumably forwardslash-separated UNC paths on Windows systems (untested). The error message however, as above, is hardcoded/fixed to the Windows paths:

// In MockFileSystem.csif(lastIndex<0){throwCommonExceptions.InvalidUncPath(nameof(path));}// In CommonExceptions.cspublicstaticArgumentExceptionInvalidUncPath(stringparamName)=>newArgumentException(@"The UNC path should be of the form \\server\share.",paramName);

Metadata

Metadata

Labels

flag: good-first-issueIssues that are good for first time contributorsstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions