ElektraInitiative / libelektra

Elektra serves as a universal and secure framework to access configuration settings in a global, hierarchical key database.
https://www.libelektra.org
BSD 3-Clause "New" or "Revised" License
206 stars 123 forks source link

libelektra-opts error codes #4953

Closed kodebach closed 5 months ago

kodebach commented 1 year ago

Noticed in #4943

libelektra-opts uses our standard errorKey system to report errors. That's sufficient, if the errors are just displayed to the user, but if you want to do additional error handling for some cases you have to attempt parsing the human-readable error message. For example:

https://github.com/ElektraInitiative/libelektra/blob/813f9c799cb94fc72e9e25ce69e1d1b2cf136053/src/tools/kdb/main.c#L135-L149

It would be nice, if elektraGetOpts set additional meta:/ keys to provide machine-readable details for the error.

For example:

# Unknown sub-command: foo
meta:/opts/error = missing_command
meta:/opts/error/command = foo

# Unknown short option: -x
meta:/opts/error = missing_option
meta:/opts/error/opt = -x

# Unknown long option: --xyz
meta:/opts/error = missing_option
meta:/opts/error/opt = --xyz

# This option cannot be repeated: -x
meta:/opts/error = repeated_option
meta:/opts/error/opt = -x

# Missing argument for short option: -x
meta:/opts/error = missing_argument
meta:/opts/error/opt = -x

# Missing argument for short option: --xyz
meta:/opts/error = missing_argument
meta:/opts/error/opt = --xyz

# This option cannot have an argument: -x
meta:/opts/error = illegal_argument
meta:/opts/error/opt = -x

# Expected at least 4  non-option arguments, but only got 3
meta:/opts/error = missing_parameter
meta:/opts/error/args/min = 4
meta:/opts/error/args/got = 3

# [All other errors]
meta:/opts/error = invalid_spec
github-actions[bot] commented 6 months ago

I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:

github-actions[bot] commented 5 months ago

I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart: