-
Notifications
You must be signed in to change notification settings - Fork 31
feat(compute): improve error message when instance not found in zone #805
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
Open
natalie-o-perret
wants to merge
1
commit into
master
Choose a base branch
from
natalieperret/sc-167368/exo-cli-minor-ux-improvement-exo-compute
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file naming does not fit in our code organization (file name -> command name). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package instance | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| v3 "github.com/exoscale/egoscale/v3" | ||
| ) | ||
|
|
||
| // findInstance looks up an instance by name or ID from a ListInstancesResponse | ||
| // and enriches the "not found" error with the zone that was searched, | ||
| // reminding the user to use -z to target a different zone. | ||
| func findInstance(resp *v3.ListInstancesResponse, nameOrID, zone string) (v3.ListInstancesResponseInstances, error) { | ||
| instance, err := resp.FindListInstancesResponseInstances(nameOrID) | ||
| if err != nil { | ||
| if errors.Is(err, v3.ErrNotFound) { | ||
| return v3.ListInstancesResponseInstances{}, fmt.Errorf( | ||
| "instance %q not found in zone %s\nHint: use -z <zone> to specify a different zone, or run 'exo compute instance list' to see instances across all zones", | ||
| nameOrID, | ||
| zone, | ||
| ) | ||
| } | ||
| return v3.ListInstancesResponseInstances{}, err | ||
| } | ||
| return instance, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/e2e/scenarios/with-api/compute/instance_not_found_error.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Test: exo compute instance <action> returns enriched error when instance not found | ||
| # Verifies that when an instance lookup fails, the error message includes the zone | ||
| # that was searched and a hint to use -z. | ||
| # No resources are created so no teardown is required. | ||
| # TEST_ZONE is injected by the API test runner. | ||
|
|
||
| # show: instance not found should mention zone and hint | ||
| ! exec exo --output-format json compute instance show nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # reboot: same helper, same enriched error | ||
| ! exec exo --output-format json compute instance reboot --force nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # stop: same helper, same enriched error | ||
| ! exec exo --output-format json compute instance stop --force nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' |
115 changes: 115 additions & 0 deletions
115
tests/e2e/scenarios/with-api/compute/instance_not_found_error_extended.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Test: all 24 instance subcommands using findInstance produce enriched not-found errors | ||
| # Companion to instance_not_found_error.txtar which covers show/reboot/stop. | ||
| # This scenario exercises the remaining 21 commands to confirm that every | ||
| # one of them surfaces the zone and the -z hint when the instance does not exist. | ||
| # No resources are created so no teardown is required. | ||
|
|
||
| # --- Actions that take only an instance name (+ optional --force) --- | ||
|
|
||
| # start | ||
| ! exec exo compute instance start --force nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # delete (without --force: findInstance error is returned directly; | ||
| # with --force the command prints a warning and exits 0 by design) | ||
| ! exec exo compute instance delete nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # update | ||
| ! exec exo compute instance update nonexistent-e2e-instance --name dummy | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # reset | ||
| ! exec exo compute instance reset --force nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # reset-password | ||
| ! exec exo compute instance reset-password nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # reveal-password | ||
| ! exec exo compute instance reveal-password nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # console-url | ||
| ! exec exo compute instance console-url nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # enable-tpm | ||
| ! exec exo compute instance enable-tpm --force nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # snapshot create | ||
| ! exec exo compute instance snapshot create nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # --- Actions that take an instance name + a second positional argument --- | ||
|
|
||
| # scale (requires instance + type) | ||
| ! exec exo compute instance scale --force nonexistent-e2e-instance standard.small | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # resize-disk (requires instance + size) | ||
| ! exec exo compute instance resize-disk --force nonexistent-e2e-instance 20 | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # snapshot revert (requires instance + snapshot-id) | ||
| ! exec exo compute instance snapshot revert --force nonexistent-e2e-instance 00000000-0000-0000-0000-000000000000 | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # security-group add (requires instance + sg name) | ||
| ! exec exo compute instance security-group add nonexistent-e2e-instance default | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # security-group remove (requires instance + sg name) | ||
| ! exec exo compute instance security-group remove nonexistent-e2e-instance default | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # private-network attach (requires instance + pn name) | ||
| ! exec exo compute instance private-network attach nonexistent-e2e-instance dummy-pn | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # private-network detach (requires instance + pn name) | ||
| ! exec exo compute instance private-network detach nonexistent-e2e-instance dummy-pn | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # private-network update-ip (requires instance + pn name) | ||
| ! exec exo compute instance private-network update-ip nonexistent-e2e-instance dummy-pn | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # elastic-ip attach (requires instance + eip) | ||
| ! exec exo compute instance elastic-ip attach nonexistent-e2e-instance 1.2.3.4 | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # elastic-ip detach (requires instance + eip) | ||
| ! exec exo compute instance elastic-ip detach nonexistent-e2e-instance 1.2.3.4 | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # ssh (requires instance; will fail at instance lookup before attempting SSH) | ||
| ! exec exo compute instance ssh nonexistent-e2e-instance | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' | ||
|
|
||
| # scp (requires instance + source + target) | ||
| ! exec exo compute instance scp nonexistent-e2e-instance /dev/null /tmp/dummy | ||
| stderr 'not found in zone' | ||
| stderr 'Hint: use -z' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is stderr redirection needed now? Put at least a note about it in the PR description so it ends up in the commit message when we merge.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a tiny detail, GitHub Action that shows an error cause of the presence of a stderr (when looking at the details, the job isn't in error, though just when you're about to expand the job output / details)