Skip to content

Commit 8ff12be

Browse files
committed
fix: expose Err() method to check for configuration errors
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 #89
1 parent eae3c18 commit 8ff12be

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

securecookie.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ type JSONEncoder struct{}
188188
// you encoding an object upstream and do not wish to re-encode it.
189189
type NopEncoder struct{}
190190

191+
// Err returns any configuration error that occurred during New or subsequent
192+
// setup calls (e.g., BlockFunc). If Err returns non-nil, all Encode and Decode
193+
// calls will fail with this error.
194+
func (s *SecureCookie) Err() error {
195+
return s.err
196+
}
197+
191198
// MaxLength restricts the maximum length, in bytes, for the cookie value.
192199
//
193200
// Default is 4096, which is the maximum value accepted by Internet Explorer.

0 commit comments

Comments
 (0)