-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix coding bugs: Replace panic with proper error handling #2296
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
base: main
Are you sure you want to change the base?
Fix coding bugs: Replace panic with proper error handling #2296
Conversation
Mirza-Samad-Ahmed-Baig
commented
Jul 14, 2025
- Replace panic() calls with proper error logging in main.go
- Fix potential nil pointer dereference when checking response.StatusCode()
- Replace panic() calls with error returns in httper.go
- Improve error handling for network operations and HTTP responses
- Replace panic() calls with proper error logging in main.go - Fix potential nil pointer dereference when checking response.StatusCode() - Replace panic() calls with error returns in httper.go - Improve error handling for network operations and HTTP responses
|
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.
Took the liberty to share some Go knowledge.
Regarding errors - can read about them here - https://preslav.me/2023/04/14/golang-error-handling-is-a-form-of-storytelling/
} | ||
if err != nil { | ||
panic(err) | ||
return "" |
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.
How is this "proper error handling"
Error should be bubbled up, so that whomever did the Post
can handle it.
Empty content might be ok in some cases
logger.Error("Failed to create route", zap.Error(err), zap.String("path", apiPath)) | ||
continue |
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 continue loading the server? This hides server loading issues, and it takes a while for whomever ran this service to know something is off (as the process didn't exit)
logger.Error("Server failed to start", zap.Error(err)) | ||
return |
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.
return is redundant
logger.Error("Server failed to start", zap.Error(err)) | |
return | |
logger.Error("Server failed to start", zap.Error(err)) |