JuliusBrussee/caveman · error
envelope: parse metadata: %w
Error message
envelope: parse metadata: %w
What it means
Open could not json.Unmarshal the stored metadata JSON into the Metadata struct. The ciphertext's companion metadata is corrupt or foreign (truncated row, wrong column, hand-edited value), so the wrapped key cannot be located and decryption must fail closed.
Source
Thrown at shared/platform/envelope/envelope.go:105
wrapped, err := secretbox.EncryptPayloadKey(dataKey)
if err != nil {
return nil, nil, fmt.Errorf("envelope: wrap data key: %w", err)
}
meta := Metadata{Scheme: scheme, WrappedDataKey: base64.StdEncoding.EncodeToString(wrapped), ScopeHash: scopeHash}
metaJSON, err = json.Marshal(meta)
if err != nil {
return nil, nil, fmt.Errorf("envelope: marshal metadata: %w", err)
}
return ciphertext, metaJSON, nil
}
// Open reverses Seal: it unwraps the data key from metadata and decrypts the
// ciphertext. An unknown scheme fails closed.
func Open(ciphertext []byte, metaJSON []byte) ([]byte, error) {
var meta Metadata
if err := json.Unmarshal(metaJSON, &meta); err != nil {
return nil, fmt.Errorf("envelope: parse metadata: %w", err)
}
if meta.Scheme == schemeV2 {
return nil, fmt.Errorf("envelope: tenant scope required for scheme %q", meta.Scheme)
}
if meta.Scheme != schemeV1 {
return nil, fmt.Errorf("envelope: unknown scheme %q", meta.Scheme)
}
return open(ciphertext, meta, nil)
}
// OpenForScope opens v2 ciphertext only for its authenticated scope. It also
// reads v1 ciphertext during migration; all new tenant-object writes use v2.
func OpenForScope(ciphertext []byte, metaJSON []byte, scope Scope) ([]byte, error) {
var meta Metadata
if err := json.Unmarshal(metaJSON, &meta); err != nil {
return nil, fmt.Errorf("envelope: parse metadata: %w", err)
}
if meta.Scheme == schemeV1 {View on GitHub (pinned to 766dce6b13)
Solutions
- Check the row for corruption; restore metadata from a backup if available
- Verify the caller is passing the metadata blob (not ciphertext or another column) to Open
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at shared/platform/envelope/envelope.go:105 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/3baa5a6e06161c60.
Report an issue: GitHub.