Tyrrrz / CliWrap

Library for running command-line processes
MIT License
4.33k stars 266 forks source link

Better exception for process not found #107

Closed Rurouni closed 3 years ago

Rurouni commented 3 years ago

At the moment if you run await Cmd("nonexistent.exe").ExecuteAsync(); it will just throw the source System.ComponentModel.Win32Exception: The system cannot find the file specified. That lacks the command name and that makes it harder to investigate the errors.

I wonder if CliWrap can intercept the error during process start and wrap it into exception with a better error message like CommandExecutionException

Thank you

Tyrrrz commented 3 years ago

That sounds reasonable.

Tyrrrz commented 3 years ago

I looked into it and unfortunately Win32Exception is also thrown in a number of different cases besides non-existing file.

CommandExecutionException is also more focused on errors that happen when the process has already exited. Perhaps a different exception should be defined for these type of errors.

I'm leaning towards closing this as "won't fix" because it sounds like a bit too much effort for little gain. I'd recommend wrapping cmd.ExecuteAsync(...) in a try/catch and throwing a specialized exception yourself.