Replace panic calls with proper error handling#7956
Conversation
- Replace panic(err) with error returns in InitFromViper methods - cmd/es-rollover/app/flags.go: Return error from InitFromViper - cmd/es-index-cleaner/app/flags.go: Return error from InitFromViper - Replace panic with error return in ParseJaegerTags - cmd/internal/flags/flags.go: Return error for invalid tag pairs - Replace panic with proper error handling in tracegen - cmd/tracegen/main.go: Handle logger creation error gracefully - Update all callers to handle returned errors - cmd/es-index-cleaner/main.go: Check InitFromViper error - cmd/es-rollover/app/actions.go: Check InitFromViper error - cmd/es-rollover/app/flags_test.go: Update test assertions - cmd/es-index-cleaner/app/flags_test.go: Update test assertions - cmd/internal/flags/flags_test.go: Update tests for error handling This improves error handling and prevents runtime crashes by properly propagating errors instead of panicking. Signed-off-by: aaryan359 <[email protected]>
|
Related Documentation No published documentation to review for changes on this repository. |
Signed-off-by: aaryan359 <[email protected]>
|
@yurishkuro, |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7956 +/- ##
=======================================
Coverage 95.58% 95.58%
=======================================
Files 316 316
Lines 16763 16766 +3
=======================================
+ Hits 16023 16026 +3
- Misses 578 579 +1
+ Partials 162 161 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@yurishkuro thanks for the review! |
There was a problem hiding this comment.
Pull request overview
This PR improves CLI robustness by removing panic()-based error handling and replacing it with returned/propagated errors that can be handled gracefully by callers.
Changes:
- Updated
ParseJaegerTagsto return(map[string]string, error)and added tests for invalid tag inputs. - Updated
es-rolloverandes-index-cleanerconfigs to return errors fromInitFromViperinstead of panicking, and updated callers/tests to handle these errors. - Adjusted tests to assert error behavior rather than panic behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cmd/internal/flags/flags.go | ParseJaegerTags now returns an error instead of panicking on invalid input. |
| cmd/internal/flags/flags_test.go | Updated tests to validate error returns and added invalid-input coverage. |
| cmd/es-rollover/app/flags.go | Config.InitFromViper now returns an error instead of panicking on TLS init failure. |
| cmd/es-rollover/app/actions.go | Propagates InitFromViper errors with context instead of assuming no-fail initialization. |
| cmd/es-rollover/app/flags_test.go | Updated to assert InitFromViper succeeds via require.NoError. |
| cmd/es-index-cleaner/app/flags.go | Config.InitFromViper now returns an error instead of panicking on TLS init failure. |
| cmd/es-index-cleaner/main.go | Caller now handles InitFromViper errors and returns them from the command. |
| cmd/es-index-cleaner/app/flags_test.go | Updated to assert InitFromViper succeeds via require.NoError. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func ParseJaegerTags(jaegerTags string) (map[string]string, error) { | ||
| if jaegerTags == "" { | ||
| return nil | ||
| return nil, nil | ||
| } |
There was a problem hiding this comment.
PR description states that cmd/tracegen/main.go was updated to replace the logger-creation panic with graceful stderr reporting, but that change is not present in this PR’s diffs. Either include the cmd/tracegen/main.go update (it currently still panics on logger build failure) or adjust the PR description/scope so it matches the actual changes.
Signed-off-by: aaryan359 <[email protected]>
Head branch was pushed to by a user without write access
|
@jkowall, now i fixed the test coverage and fixed the description also . can this meged now |
Signed-off-by: aaryan359 <[email protected]>
This PR replaces several `panic()` calls with proper error handling across Jaeger CLI tools, improving robustness and preventing unexpected runtime crashes. ## Which problem is this PR solving? - Resolves jaegertracing#7955 ## Description of the changes - Replaced `panic(err)` with error returns in `InitFromViper` methods - `cmd/es-rollover/app/flags.go` - `cmd/es-index-cleaner/app/flags.go` - Updated `ParseJaegerTags` to return an error for invalid tag pairs - `cmd/internal/flags/flags.go` - Updated all callers to properly handle returned errors - `cmd/es-index-cleaner/main.go` - `cmd/es-rollover/app/actions.go` - Updated and extended tests to assert error conditions instead of panics - `cmd/es-rollover/app/flags_test.go` - `cmd/es-index-cleaner/app/flags_test.go` - `cmd/internal/flags/flags_test.go` These changes align with Go best practices and improve CLI stability without changing functionality. ## How was this change tested? - `make fmt` - `make lint` - `make test` All tests pass successfully. ## Checklist - [x] I have read the contributing guidelines - [x] I have signed all commits - [x] I have added/updated unit tests where applicable - [x] I have run lint and test steps successfully --------- Signed-off-by: aaryan359 <[email protected]>
This PR replaces several `panic()` calls with proper error handling across Jaeger CLI tools, improving robustness and preventing unexpected runtime crashes. ## Which problem is this PR solving? - Resolves jaegertracing#7955 ## Description of the changes - Replaced `panic(err)` with error returns in `InitFromViper` methods - `cmd/es-rollover/app/flags.go` - `cmd/es-index-cleaner/app/flags.go` - Updated `ParseJaegerTags` to return an error for invalid tag pairs - `cmd/internal/flags/flags.go` - Updated all callers to properly handle returned errors - `cmd/es-index-cleaner/main.go` - `cmd/es-rollover/app/actions.go` - Updated and extended tests to assert error conditions instead of panics - `cmd/es-rollover/app/flags_test.go` - `cmd/es-index-cleaner/app/flags_test.go` - `cmd/internal/flags/flags_test.go` These changes align with Go best practices and improve CLI stability without changing functionality. ## How was this change tested? - `make fmt` - `make lint` - `make test` All tests pass successfully. ## Checklist - [x] I have read the contributing guidelines - [x] I have signed all commits - [x] I have added/updated unit tests where applicable - [x] I have run lint and test steps successfully --------- Signed-off-by: aaryan359 <[email protected]>
This PR replaces several
panic()calls with proper error handling across Jaeger CLI tools, improving robustness and preventing unexpected runtime crashes.Which problem is this PR solving?
Description of the changes
panic(err)with error returns inInitFromVipermethodscmd/es-rollover/app/flags.gocmd/es-index-cleaner/app/flags.goParseJaegerTagsto return an error for invalid tag pairscmd/internal/flags/flags.gocmd/es-index-cleaner/main.gocmd/es-rollover/app/actions.gocmd/es-rollover/app/flags_test.gocmd/es-index-cleaner/app/flags_test.gocmd/internal/flags/flags_test.goThese changes align with Go best practices and improve CLI stability without changing functionality.
How was this change tested?
make fmtmake lintmake testAll tests pass successfully.
Checklist