AlexxIT/go2rtc · error
credentials: storage not initialized
Error message
credentials: storage not initialized
What it means
pkg/creds/creds.go:24 backs the credential store with a package-level storage set via SetStorage. SetValue checks that storage first; if SetStorage was never called (storage == nil) it returns "credentials: storage not initialized". The library deliberately fails fast instead of silently dropping credentials — there is nowhere to persist the value.
Solutions
- Call creds.SetStorage(impl) at startup before any SetValue, with a real Storage implementation.
- If you don't need persistence, use the library's provided in-memory/file storage implementation rather than leaving storage nil.
- Fix initialization order so SetStorage runs in main/init before workers call SetValue.
- Wrap SetValue calls with a check/error message pointing to the missing SetStorage call.
Example fix
// before
func main() {
_ = creds.SetValue("camera_password", "secret") // storage not initialized
}
// after
func main() {
creds.SetStorage(NewFileStorage("/data/creds.json"))
_ = creds.SetValue("camera_password", "secret")
} Defensive patterns
Strategy: validation
Validate before calling
if !credsInitialized { // set true right after SetStorage
return errors.New("call creds.SetStorage before using credentials")
} Try / catch
if err := creds.SetValue(name, value); err != nil && strings.Contains(err.Error(), "storage not initialized") {
return fmt.Errorf("credentials backend missing: %w (call creds.SetStorage at startup)", err)
} Prevention
- Call creds.SetStorage as the first step of main/init
- Add a smoke test that SetValue works in your binary
- Never delay storage setup behind lazy paths
- Use the library's provided storage implementations
When it happens
Trigger: Calling creds.SetValue (directly or via anything that stores credentials) in a process where creds.SetStorage(s) was never invoked — e.g. a service that uses this library without wiring a credentials backend (file, database, etc.).
Common situations: Embedding the library in a custom binary while forgetting to initialize the creds backend at startup; running components (tests, CLI tools) that skip the storage setup step; ordering bug where SetValue runs before SetStorage during init.
Related errors
- hap: can't dial witout client_id or client_private
- multipart: no receivers
- nest: unable to find cached credentials
- nest: wrong query
- wrong user/pass
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/50e391784e936fd4.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/creds/creds.go:24
"path/filepath"
"regexp"
"strings"
)
type Storage interface {
SetValue(name, value string) error
GetValue(name string) (string, bool)
}
var storage Storage
func SetStorage(s Storage) {
storage = s
}
func SetValue(name, value string) error {
if storage == nil {
return errors.New("credentials: storage not initialized")
}
if err := storage.SetValue(name, value); err != nil {
return err
}
AddSecret(value)
return nil
}
func GetValue(name string) (value string, ok bool) {
value, ok = getValue(name)
AddSecret(value)
return
}
func getValue(name string) (string, bool) {
if storage != nil {
if value, ok := storage.GetValue(name); ok {
return value, trueView on GitHub (pinned to c245815e75)