{"record":{"id":"9a17e86dcc80b9db","repo":"cayleygraph/cayley","slug":"unexpected-int-size-d","errorCode":null,"errorMessage":"unexpected int size: %d","messagePattern":"unexpected int size: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/kv/quadstore.go","lineNumber":291,"sourceCode":"\t\tif err == kv.ErrNotFound {\n\t\t\treturn ErrNoBucket\n\t\t} else if err != nil {\n\t\t\treturn err\n\t\t}\n\t\tvers, err = asInt64(val, 0)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn nil\n\t})\n\treturn vers, err\n}\n\nfunc asInt64(b []byte, empty int64) (int64, error) {\n\tif len(b) == 0 {\n\t\treturn empty, nil\n\t} else if len(b) != 8 {\n\t\treturn 0, fmt.Errorf(\"unexpected int size: %d\", len(b))\n\t}\n\tv := int64(binary.LittleEndian.Uint64(b))\n\treturn v, nil\n}\n\nfunc (qs *QuadStore) horizon(ctx context.Context) int64 {\n\th, _ := qs.getMetaInt(ctx, \"horizon\")\n\treturn h\n}\n\nfunc (qs *QuadStore) ValuesOf(ctx context.Context, vals []graph.Ref) ([]quad.Value, error) {\n\tout := make([]quad.Value, len(vals))\n\tvar (\n\t\tinds  []int\n\t\tirefs []uint64\n\t)\n\tfor i, v := range vals {\n\t\tif v == nil {","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/kv/quadstore.go#L273-L309","documentation":"asInt64 decodes a fixed 8-byte little-endian int64 value stored in the KV-backed quadstore. Empty bytes are treated as a sentinel returning the caller-provided 'empty' default, but any other length that is not exactly 8 bytes cannot be a stored int64, so the function rejects it. This guards against corrupted or wrong-encoding data in the underlying key-value database.","triggerScenarios":"Calling QuadStore horizon/counter accessors (e.g. via QuadStore internals that call asInt64) when the value bytes read from the KV store are not exactly 8 bytes long — typically because the key holds differently encoded data, the value was written by another version of the store with a different encoding, or the database is corrupted/truncated.","commonSituations":"Opening a database written by an incompatible Cayley/kv schema version; manual edits or corruption of the Bolt/badger DB file; a truncated value due to an interrupted write; pointing the quadstore at a KV bucket written by a different tool.","solutions":["Check that the database was created by the same version of the library and was not written with a different encoding","Verify database integrity or rebuild the store by re-importing the source data into a fresh database","Inspect the offending key's value length to confirm corruption before further use","Restore from a known-good backup of the KV database"],"exampleFix":"// before: reading raw bytes without validation\nv, err := asInt64(raw, 0)\n// after: guard length before decoding\nif len(raw) != 0 && len(raw) != 8 {\n    return 0, fmt.Errorf(\"unexpected int size: %d\", len(raw))\n}\nv, err := asInt64(raw, 0)","handlingStrategy":"validation","validationCode":"if len(raw) != 0 && len(raw) != 8 {\n    return fmt.Errorf(\"value not an 8-byte int64: %d bytes\", len(raw))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the same library version that created the database","Do not hand-edit KV database files","Back up the database and verify integrity before upgrades"],"tags":["kv-store","data-corruption","encoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}