{"record":{"id":"3351c3dc75457ea3","repo":"cayleygraph/cayley","slug":"couldn-t-decode-value-v","errorCode":null,"errorMessage":"couldn't decode value: %v","messagePattern":"couldn't decode value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/nosql/quadstore.go","lineNumber":544,"sourceCode":"\t}\n\tvar err error\n\t// prefer protobuf representation\n\tif v, ok := d[fldValPb]; ok {\n\t\tvar b []byte\n\t\tswitch v := v.(type) {\n\t\tcase nosql.String:\n\t\t\tb, err = base64.StdEncoding.DecodeString(string(v))\n\t\tcase nosql.Bytes:\n\t\t\tb = []byte(v)\n\t\tdefault:\n\t\t\terr = fmt.Errorf(\"unexpected type for pb field: %T\", v)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tvar p pquads.Value\n\t\tif err := proto.Unmarshal(b, &p); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"couldn't decode value: %v\", err)\n\t\t}\n\t\treturn p.ToNative(), nil\n\t} else if v, ok := d[fldValInt]; ok {\n\t\tif opt.Number32 {\n\t\t\t// parse from string, so we are confident that we will get exactly the same value\n\t\t\tif vs, ok := d[fldValStrInt].(nosql.String); ok {\n\t\t\t\tiv := quad.Int(stoi(string(vs)))\n\t\t\t\treturn iv, nil\n\t\t\t}\n\t\t}\n\t\tvi, err := asInt(v)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn quad.Int(vi), nil\n\t} else if v, ok := d[fldValFloat]; ok {\n\t\tvar vf quad.Float\n\t\tswitch v := v.(type) {","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/nosql/quadstore.go#L526-L562","documentation":"After successfully obtaining the raw bytes of a protobuf value, toQuadValue runs proto.Unmarshal into pquads.Value; this error wraps any unmarshal failure. The bytes exist but are not a valid pquads.Value message — the stored blob is malformed, truncated, or encoded by an incompatible proto schema.","triggerScenarios":"Reading a fldValPB field whose bytes were corrupted (partial write), hand-edited, or written with a different protobuf schema/version so Unmarshal fails.","commonSituations":"Interrupted bulk import leaving truncated value blobs; schema drift between Cayley versions of pquads.Value; custom tooling writing wrong bytes into the pb field.","solutions":["Identify the affected documents and delete/rewrite their value fields with a fresh proto.Marshal(pquads.Value).","Dump and re-import the store to regenerate all protobuf value blobs.","Confirm the pquads proto schema version matches the Cayley version reading the data.","If the error is transient storage corruption, restore from backup or re-run the import that wrote the values."],"exampleFix":"// before\nif err := proto.Unmarshal(b, &p); err != nil {\n    return nil, fmt.Errorf(\"couldn't decode value: %v\", err)\n}\n// after\n// writer side: ensure valid encoding\nraw, err := proto.Marshal(&pquads.Value{...})\nif err != nil { return err }\ndoc[fldValPB] = nosql.Bytes(raw)","handlingStrategy":"try-catch","validationCode":"// sanity check blob non-empty before unmarshal\nif len(b) == 0 {\n    return nil, errors.New(\"empty pb value blob\")\n}","typeGuard":null,"tryCatchPattern":"val, err := toQuadValue(opt, doc)\nif err != nil && strings.HasPrefix(err.Error(), \"couldn't decode value\") {\n    log.Printf(\"corrupt protobuf value, dropping doc: %v\", err)\n    return quad.Raw(\"\"), nil\n}","preventionTips":["Don't interrupt bulk imports mid-write; resume rather than kill","Keep the pquads proto schema version consistent with reader","Back up the store before migrations","Re-import corrupted value blobs via proto.Marshal of a fresh pquads.Value"],"tags":["protobuf","unmarshal","data-corruption","cayley"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}