Skip to content

fix: expose Err() method to check for configuration errors#90

Open
Yanhu007 wants to merge 1 commit intogorilla:mainfrom
Yanhu007:fix/expose-new-error
Open

fix: expose Err() method to check for configuration errors#90
Yanhu007 wants to merge 1 commit intogorilla:mainfrom
Yanhu007:fix/expose-new-error

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #89

Problem

New() silently stores configuration errors (missing hash key, invalid block cipher key) in a private err field. There is no way for callers to check if New() succeeded — they only discover the problem when Encode()/Decode() later returns an error.

s := securecookie.New(nil, nil) // no error returned!
_, err := s.Encode("session", value) // fails here with cryptic error

Fix

Add a public Err() method:

func (s *SecureCookie) Err() error

This lets callers check for misconfiguration immediately:

s := securecookie.New(hashKey, blockKey)
if err := s.Err(); err != nil {
    log.Fatalf("securecookie setup failed: %v", err)
}

This is backward-compatible — no existing API signatures change. All existing tests pass.

New() silently stores configuration errors (e.g., missing hash key,
invalid block key) in a private field. Users have no way to detect
these errors until Encode/Decode fails.

Add a public Err() method that returns any stored configuration
error, allowing callers to check for misconfiguration immediately
after calling New().

Fixes gorilla#89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Silent errors on New()

1 participant