Skip to content

Commit

Permalink
Even better errors for incorrect usage
Browse files Browse the repository at this point in the history
Split file not found from wrong extension; was still a bit unclear.
  • Loading branch information
timabell committed Feb 15, 2024
1 parent 88aaaa3 commit 9c9486b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/CLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ public int Run(string[] args)
} catch(InvalidSlnPathException ex) {
Console.Error.WriteLine(ex.Message);
return 2;
} catch(PathNotFoundException ex) {
} catch(SlnFileNotFoundException ex) {
Console.Error.WriteLine(ex.Message);
return 3;
} catch(PathNotFoundException ex) {
Console.Error.WriteLine(ex.Message);
return 4;
} catch(EmptyPathListException) {
Console.Error.WriteLine("No paths supplied to sync with.");
Console.Error.WriteLine("Supply a list of folder/file arguments that you want to be sync'd into the target solution folder.");
Console.Error.WriteLine();
WriteUsage();
return 4;
return 5;
}

Console.Out.WriteLine("Sync completed.");
Expand Down
13 changes: 9 additions & 4 deletions src/SlnSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ public SlnSync() : this(new DefaultGuidGenerator())
/// <param name="paths">list of paths to recursively add/update SolutionItems virtual folders with</param>
public void SyncSlnFile(string slnPath, string slnFolder, IEnumerable<string> paths)
{
if (!File.Exists(slnPath) || !slnPath.EndsWith(".sln"))
if (!slnPath.EndsWith(".sln"))
{
throw new InvalidSlnPathException($"'{slnPath}' is not a sln file");
throw new InvalidSlnPathException(slnPath);
}
if (!File.Exists(slnPath))
{
throw new SlnFileNotFoundException(slnPath);
}
if (!paths.Any())
{
Expand Down Expand Up @@ -121,6 +125,7 @@ private SolutionFolder FindOrCreateSolutionFolder(ICollection<IProject> solution
=> solutionProjects.OfType<SolutionFolder>().FirstOrDefault(project => project.Name == folderName);
}

public class PathNotFoundException(string path) : Exception($"Path '{path}' not found");
public class InvalidSlnPathException(string s) : Exception(s);
public class PathNotFoundException(string path) : Exception($"Path not found: '{path}'");
public class SlnFileNotFoundException(string path) : Exception($"Invalid .sln file '{path}' - File not found.");
public class InvalidSlnPathException(string path) : Exception($"Invalid .sln file '{path}' - File must have .sln extension");
public class EmptyPathListException() : Exception();

0 comments on commit 9c9486b

Please sign in to comment.