Skip to content

Conversation

@vpetersson
Copy link
Contributor

What does this PR do?

This PR fixes a panic that occurred in the get_app function within the edge-app API module. Previously, if the API call returned an empty list (indicating the requested edge app ID was not found), the code would attempt to access the first element of the empty list, causing an index out of bounds panic.

This change introduces a check for an empty list in get_app. If the list is empty, it now returns a CommandError::ResourceNotFound error. Additionally, the ResourceNotFound variant has been added to the CommandError enum definition to support this.

GitHub issue or Phabricator ticket number?

N/A

How has this been tested?

The full test suite was executed using cargo test after applying the changes, and all tests passed successfully. This verifies that the fix resolves the compilation error and integrates correctly with the existing codebase.

The `get_app` function panicked when trying to access the first element
of the returned app list if the list was empty (e.g., app not found).

This commit adds a check for an empty list in `get_app` and returns
a `ResourceNotFound` error in that case. It also adds the
`ResourceNotFound` variant to the `CommandError` enum.
@vpetersson
Copy link
Contributor Author

@sergey-borovkov This is the error this should address:

thread 'main' panicked at src/api/edge_app/app.rs:76:61:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@vpetersson vpetersson merged commit c308a87 into master Apr 21, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants