Replace unhandled panics with proper error returns in microcks_client#404
Open
PranjaliBhardwaj wants to merge 1 commit into
Open
Replace unhandled panics with proper error returns in microcks_client#404PranjaliBhardwaj wants to merge 1 commit into
PranjaliBhardwaj wants to merge 1 commit into
Conversation
Signed-off-by: Pranjali Bhardwaj <pranjalisharma6543@gmail.com>
|
Welcome to the Microcks community! 💖 Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly. Hope you have a great time there! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
in pkg/connectors/microcks_client.go, I noticed that several methods were using panic(err) when reading HTTP response bodies or unmarshaling JSON. If the Microcks server returns a bad response or there's a network blip, this would completely crash the CLI.
I went through and swapped out all those panic calls for proper fmt.Errorf returns in the functions that already have an error return type. this way the errors bubble up properly and we can handle them gracefully instead of just dying on the spot.
Implementation details
Removed panic(err) in NewClient, GetKeycloakURL, CreateTestResult, GetTestResult, and UploadArtifact.
Replaced them with context-wrapped errors (e.g. fmt.Errorf("failed to read test result response body: %w", err)).
In CreateTestResult, I also added a safe type assertion check (testID, ok := createTestResp["id"].(string)) so it doesn't panic if the id field happens to be missing or isn't a string.
Testing
Built the CLI locally.
Intentionally caused some network failures/invalid JSON responses and verified that the CLI now prints a clean error message and exits normally instead of throwing a stack trace panic.
Related issue(s) #403