What's wrong
Program.Main returns void and throws away the parser result (FileDeduplicator/Program.cs:15-21). BaseVerb.Run() and each verb's Run also return void (Verbs/BaseVerb.cs:21,33). As a result, the process exits with 0 on every path except an unhandled crash, including:
- a
-p directory that doesn't exist
Deduplicate finishing with deletion errors (result.Errors.Count > 0)
- the user aborting at a prompt
- unknown or invalid command-line options
Why it matters
A script or scheduled job has no way to tell a failed run from a successful one. For example, FileDeduplicator Deduplicate -p /data && echo done reports success when none of the duplicates were deleted.
Reproduction
These were run against the built ktsu.FileDeduplicator.dll on Linux:
| Command |
Output |
Exit code |
Scan -p /nonexistent |
Directory not found: /nonexistent / Found 0 file(s). |
0 |
Scan --nope |
help and parse errors |
0 |
Running as a user without write permission on the directory holding a duplicate, echo y | Deduplicate -p <dir> |
Error deleting …: Access to the path … is denied. / Deleted 0 file(s). / Encountered 1 error(s) during deletion. |
0 |
Suggested fix
- Change
Main to static int Main(string[] args) and use ParseArguments(...).MapResult(...), returning 2 when parsing fails.
- Have
BaseVerb.Run / Run(T) return an int exit code:
0 on success
1 when the directory is missing, when the user aborts, or when Deduplicate finishes with Errors.Count > 0
- Add tests that check the exit code in each of these cases.
What's wrong
Program.Mainreturnsvoidand throws away the parser result (FileDeduplicator/Program.cs:15-21).BaseVerb.Run()and each verb'sRunalso returnvoid(Verbs/BaseVerb.cs:21,33). As a result, the process exits with 0 on every path except an unhandled crash, including:-pdirectory that doesn't existDeduplicatefinishing with deletion errors (result.Errors.Count > 0)Why it matters
A script or scheduled job has no way to tell a failed run from a successful one. For example,
FileDeduplicator Deduplicate -p /data && echo donereports success when none of the duplicates were deleted.Reproduction
These were run against the built
ktsu.FileDeduplicator.dllon Linux:Scan -p /nonexistentDirectory not found: /nonexistent/Found 0 file(s).Scan --nopeecho y | Deduplicate -p <dir>Error deleting …: Access to the path … is denied./Deleted 0 file(s)./Encountered 1 error(s) during deletion.Suggested fix
Maintostatic int Main(string[] args)and useParseArguments(...).MapResult(...), returning2when parsing fails.BaseVerb.Run/Run(T)return anintexit code:0on success1when the directory is missing, when the user aborts, or whenDeduplicatefinishes withErrors.Count > 0