Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set and document exit codes #215

Closed
kwin opened this issue Feb 18, 2021 · 7 comments
Closed

Set and document exit codes #215

kwin opened this issue Feb 18, 2021 · 7 comments
Labels
help wanted Extra attention is needed released

Comments

@kwin
Copy link
Contributor

kwin commented Feb 18, 2021

To ease usage of the cli in non-interactive environments it would be good to set and document the process exit codes in case of failures for each command.
Currently always the default exit code (0 = SUCCESS) is used.

For that https://oclif.io/docs/commands#thiserrormessage-string--error-options-code-string-exit-number-ref-string-suggestions-string has to be used (e.g. in

).

A mapping of the codes in https://github.com/adobe/aio-lib-cloudmanager/blob/1ec31d3234b97e09840864ed6eadaf7231e89914/src/SDKErrors.js#L51 and an exit code should be established.

@kwin kwin changed the title Document exit codes Set and document exit codes Feb 22, 2021
@kwin
Copy link
Contributor Author

kwin commented Feb 23, 2021

Instead of catching the exceptions individually per command a catch method (https://oclif.io/docs/error_handling) can be implemented in base-*-command which

  1. stops the spinner
  2. emits an error message derived from the exception
  3. returns an exit code derived from the exception

In most of the cases the thrown exceptions should be an instance of https://github.com/adobe/aio-lib-core-errors#aiocoresdkerror

@justinedelson
Copy link
Member

See my comment in #224 -- I think there's a generalized issue here related to non-interactive use.

@kwin
Copy link
Contributor Author

kwin commented Apr 6, 2021

Actually calling Command.error with a string as first parameter uses the exit code 1 by default (https://github.com/oclif/errors/blob/95b0ea57bb23d0c4fcb0d877260418387e940492/src/handle.ts#L22). Would still be good to improve this, so that the exit code gets some more meaning (and you can derive the underlying exception from it).

@robrat
Copy link

robrat commented Aug 2, 2021

Is there any progress in exit code handling? On Friday and today we have seen in our Github workflows that the aio cloudmanager commands do not work because the key expired, but this was returned as success to the pipeline:

$ aio cloudmanager:pipeline:update <id> --tag="v2.3.4"
updating pipeline... 400 - {"error_description":"Could not match JWT signature to any of the bindings","error":"invalid_token"}

$ echo $?
0

$ aio cloudmanager:pipeline:create-execution <id>
starting execution... 400 - {"error_description":"No valid bindings were found for organization and technical account combination","error":"invalid_token"}

$ echo $?
0

The Adobe IO CLI tools used in the Github workflow:

@adobe/aio-cli: 8.0.0
@adobe/aio-cli-plugin-cloudmanager: 2.4.3

@justinedelson justinedelson added the help wanted Extra attention is needed label Aug 2, 2021
@justinedelson
Copy link
Member

hmm. I guess I misunderstood @kwin's last comment. I thought that the exit code would be 1 (although strangely in my testing it seems to be 2, not 1). But it appears that this is inconsistent because error is not used throughout -- in cases like these, action.start and action.stop are used and that exit code behavior is specific to error.

So I fear that what @kwin originally suggested is necessary -- extract the catch blocks from all of the commands and do it centrally.

@justinedelson
Copy link
Member

Looking at the options available, I think it is achievable to set four distinct exit codes:

1 - A generic error has occurred
2 - A configuration error has occurred
3 - A validation error with the supplied flags or arguments has occurred
30 - An error emanating from the Cloud Manager SDK has occurred

While I understand the desire to have a unique exit code per error, I don't think that's practical, both due to internal API limitations and because it is not unimaginable that the Cloud Manager SDK could soon emit more than 255 unique error codes.

github-actions bot pushed a commit that referenced this issue Aug 3, 2021
# [2.5.0](2.4.3...2.5.0) (2021-08-03)

### Features

* **errors:** implement consistent error codes and exit codes. fixes [#215](#215) ([#428](#428)) ([e6a796c](e6a796c))
@github-actions
Copy link

github-actions bot commented Aug 3, 2021

🎉 This issue has been resolved in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed released
Projects
None yet
Development

No branches or pull requests

3 participants