Module: Aspera::Cli::ExitCode
- Defined in:
- lib/aspera/cli/error.rb
Overview
Exit status of the process, by category of error
Constant Summary collapse
- SUCCESS =
0- ERROR =
1- USAGE =
2- AUTH =
3- NOT_FOUND =
4- TRANSFER =
5- NETWORK =
6- API =
7- INTERRUPTED =
128 + SIGINT, as shells do
130- DESCRIPTIONS =
For help and documentation
{ SUCCESS => 'Success', ERROR => 'Other error', USAGE => 'Command line error: unknown command or option, invalid or missing argument', AUTH => 'Authentication or authorization failure: SSH, HTTP 401 or 403, OAuth grant', NOT_FOUND => 'Resource not found, or several resources match the identifier, HTTP 404', TRANSFER => 'Transfer failure', NETWORK => 'Network or TLS failure: name resolution, connection, timeout, certificate', API => 'Other error returned by a remote API', INTERRUPTED => 'Interrupted by user (Ctrl-C)' }.freeze
Class Method Summary collapse
-
.add_error(error_class, label:, code:) ⇒ nil
Add the category of an error class (and its subclasses) raised by code that is not of the CLI, e.g.
-
.error_category(error) ⇒ Hash?
labelandcodeof the most specific added class of the error (whatever the order ofadd_error),nilif none. -
.for_call_error(error) ⇒ Integer
Exit code for the HTTP status, or OAuth error.
Class Method Details
.add_error(error_class, label:, code:) ⇒ nil
Add the category of an error class (and its subclasses) raised by code that is not of the CLI, e.g. the domain library used by a bundle.
The runner gives such an error its label and exit code, instead of Other.
45 46 47 48 49 50 |
# File 'lib/aspera/cli/error.rb', line 45 def add_error(error_class, label:, code:) raise ArgumentError, "not an error class: #{error_class}" unless error_class.is_a?(Class) && error_class <= StandardError raise ArgumentError, "unknown exit code: #{code}" unless DESCRIPTIONS.key?(code) @errors[error_class] = {label: label, code: code}.freeze nil end |
.error_category(error) ⇒ Hash?
Returns label and code of the most specific added class of the error (whatever the order of add_error), nil if none.
54 55 56 57 |
# File 'lib/aspera/cli/error.rb', line 54 def error_category(error) error.class.ancestors.each { |klass| return @errors[klass] if @errors.key?(klass) } nil end |
.for_call_error(error) ⇒ Integer
Returns Exit code for the HTTP status, or OAuth error.
61 62 63 64 65 66 67 68 |
# File 'lib/aspera/cli/error.rb', line 61 def for_call_error(error) return AUTH if error.data.is_a?(Hash) && OAUTH_AUTH_ERRORS.include?(error.data['error']) case error.response&.code when '401', '403' then AUTH when '404' then NOT_FOUND else API end end |