-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Labels
☢️ BugSomething isn't workingSomething isn't working
Description
Bug Description
Redis storage constructor panic on network or flushing errors.
Using panic
in a public library (especially one intended for integration like fiber/storage/redis
) breaks Go’s normal error-handling semantics and prevents callers from gracefully handling startup failures.
Why this is problematic:
- Panics in public libraries break normal error handling and make it impossible for applications to gracefully recover or report failures.
Go libraries should return errors, not crash the process. - Implicit IO (PING) during object creation violates constructor expectations-
New()
should only allocate and configure objects, not perform external network calls.
This makes testing, offline environments, and lazy initialization harder.
How to Reproduce
Steps to reproduce the behavior:
- Call
New()
with address that doesn't exist or not reachable. - The process will crash.
Expected Behavior
The constructor should:
- Return (*Storage, error) instead of panicking.
- Avoid performing an implicit PING during initialization.
- Let the caller decide whether to verify connectivity or defer it.
Storage package Version
v3.4.1
Code Snippet (optional)
// New creates a new Redis storage instance.
func New(config ...Config) *Storage {
// Set default config
cfg := configDefault(config...)
// ........
// Test connection
if err := db.Ping(context.Background()).Err(); err != nil {
panic(err)
}
// Empty collection if Clear is true
if cfg.Reset {
if err := db.FlushDB(context.Background()).Err(); err != nil {
panic(err)
}
}
// Create new store
return &Storage{
db: db,
}
}
Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my problem prior to opening this one.
- I understand that improperly formatted bug reports may be closed without explanation.
Metadata
Metadata
Assignees
Labels
☢️ BugSomething isn't workingSomething isn't working