Skip to content

Replace unhandled panics with proper error returns in microcks_client#404

Open
PranjaliBhardwaj wants to merge 1 commit into
microcks:masterfrom
PranjaliBhardwaj:newa
Open

Replace unhandled panics with proper error returns in microcks_client#404
PranjaliBhardwaj wants to merge 1 commit into
microcks:masterfrom
PranjaliBhardwaj:newa

Conversation

@PranjaliBhardwaj
Copy link
Copy Markdown
Contributor

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

Signed-off-by: Pranjali Bhardwaj <pranjalisharma6543@gmail.com>
@github-actions
Copy link
Copy Markdown

👋 @PranjaliBhardwaj

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!

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.

1 participant