{"record":{"id":"f877cfd69bc5478a","repo":"getsops/sops","slug":"internal-error-unexpected-metadata-conversion-res","errorCode":null,"errorMessage":"Internal error: unexpected metadata conversion result %T","messagePattern":"Internal error: unexpected metadata conversion result %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"stores/metadata.go","lineNumber":265,"sourceCode":"\tconfig := mapstructure.DecoderConfig{\n\t\tResult: &mdMap,\n\t}\n\td, err := mapstructure.NewDecoder(&config)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\terr = d.Decode(md)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tmetadata, err := goToSops(mdMap)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif tb, ok := metadata.(sops.TreeBranch); ok {\n\t\treturn tb, nil\n\t}\n\treturn nil, fmt.Errorf(\"Internal error: unexpected metadata conversion result %T\", metadata)\n}\n\n// SerializeMetadata embeds the metadata of `data` into its tree branches.\nfunc SerializeMetadata(data sops.Tree, opts MetadataOpts) (sops.TreeBranches, error) {\n\tmd, err := metadataToTreeBranch(metadataFromInternal(data.Metadata))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error while serializing metadata: %w\", err)\n\t}\n\tif opts.Flatten != MetadataFlattenNone {\n\t\tvar prefix string\n\t\tif opts.Flatten == MetadataFlattenFull {\n\t\t\tprefix = SopsPrefix\n\t\t}\n\t\tmd, err = flattenTreeBranch(md, prefix)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Error while flattening metadata: %w\", err)\n\t\t}\n\t\tif opts.EscapeNewlines {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/stores/metadata.go#L247-L283","documentation":"An internal invariant failure in metadataToTreeBranch: the internal metadata conversion (goMapToInternal→convertMetadata) returned a value that is not a sops.TreeBranch. This should be impossible with valid code paths, so the error indicates an unexpected programming-level inconsistency rather than bad user input.","triggerScenarios":"Calling SerializeMetadata (directly or via EmitEncryptedFile) when the metadata conversion pipeline returns a non-TreeBranch value — realistically only via a modified/patched library, a custom Metadata type, or a genuine sops bug.","commonSituations":"Forked or monkey-patched sops code, custom builds where the metadata conversion was altered, or a library bug — end users of stock sops should essentially never see this.","solutions":["Report the issue upstream to sops with the wrapped input metadata and version","Pin/return to an official sops release instead of a custom build","Verify no local modifications changed the metadata conversion return type","As a workaround, rebuild the tree via standard APIs (LoadEncryptedFile → EmitEncryptedFile) rather than custom conversion"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"tb, err := stores.SerializeMetadata(tree, opts)\nif err != nil {\n\tif strings.Contains(err.Error(), \"Internal error: unexpected metadata conversion result\") {\n\t\treturn fmt.Errorf(\"sops internal invariant violated; report upstream with version and repro: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Use official sops releases, not patched forks","Avoid altering the metadata conversion pipeline","Populate trees via standard APIs (LoadEncryptedFile)","Report occurrences upstream as library bugs"],"tags":["internal","invariant","metadata","bug"],"backgroundTag":"internal-metadata-invariant-violation","analyzedSha":"13442bb98183887d7a9ac09ec8ab0564673a59d8","analyzedAt":"2026-09-01T03:53:00.447Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}