Skip to content

Every verb exits with code 0 even when the directory is missing, deletions fail, or the arguments are invalid #144

Description

@matt-edmondson

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreadyFully specified; implement as written

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions