Argu
Argu copied to clipboard
Expose ArguParseException or similar for use within apps
Description
Would like a way to throw ArguParseException, either directly or indirectly via a helper.
e.g. missingArg or invalidCommand of string -> 'a that would raise (ArguParseException("ERROR: " + message)) or similar
Expected behavior
Can handle 2% of cases where I determine that semantics have been contravened by the invocation, but can't represent that rule via attributes and/or Argu API calls
Actual behavior
Need to define my own exception for that, and then remember to handle it explicitly as I already need to for ArguParseException
Known workarounds
In Equinox, Propulsion and some closed source apps, I and others have established a convention of having a secondary exception (MissingArg)
- example codebase: https://github.com/jet/propulsion/search?q=MissingArg
- most ugly bit is https://github.com/jet/propulsion/blob/2bbe428cdb99e229d7f21c3ac389b73bbb64a822/tools/Propulsion.Tool/Program.fs#L282
- but having to provide handling such as https://github.com/jet/propulsion/blob/2bbe428cdb99e229d7f21c3ac389b73bbb64a822/tools/Propulsion.Tool/Program.fs#L285 is also not ideal
I do appreciate that there is a value in ArguParseException being known and trusted to only be throwable indirectly by invoking Argu operations.
If the exception was a type rather than an exception, I'd be proposing a derived Exception type as a solution that solves my desire to be able to filter with a single type check pattern, but I suspect that's a bridge too far.
Am absolutely interested in spike PRs that demonstrate cleaner ways to handle cases where e.g. I'm seeking to convey programmatically that that some combination of arguments are missing and/or illegal.
I ended up with a mix of ParseResults.Catch / Raise / GetResult in Equinox and Propulsion
https://github.com/jet/propulsion/blob/8349a25fd9abda31922210f710c716fcf190305c/tools/Propulsion.Tool/Args.fs#L33 https://github.com/jet/propulsion/blob/8349a25fd9abda31922210f710c716fcf190305c/tools/Propulsion.Tool/Infrastructure.fs#L13-L16 https://github.com/jet/propulsion/blob/8349a25fd9abda31922210f710c716fcf190305c/tools/Propulsion.Tool/Program.fs#L404
Ultimately if #143 had a complete answer, I would probably not be looking for anything here, and #187 is a reasonable half way house