cayleygraph/cayley · error
unexpected int size: %d
Error message
unexpected int size: %d
What it means
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.
Source
Thrown at graph/kv/quadstore.go:291
if err == kv.ErrNotFound {
return ErrNoBucket
} else if err != nil {
return err
}
vers, err = asInt64(val, 0)
if err != nil {
return err
}
return nil
})
return vers, err
}
func asInt64(b []byte, empty int64) (int64, error) {
if len(b) == 0 {
return empty, nil
} else if len(b) != 8 {
return 0, fmt.Errorf("unexpected int size: %d", len(b))
}
v := int64(binary.LittleEndian.Uint64(b))
return v, nil
}
func (qs *QuadStore) horizon(ctx context.Context) int64 {
h, _ := qs.getMetaInt(ctx, "horizon")
return h
}
func (qs *QuadStore) ValuesOf(ctx context.Context, vals []graph.Ref) ([]quad.Value, error) {
out := make([]quad.Value, len(vals))
var (
inds []int
irefs []uint64
)
for i, v := range vals {
if v == nil {View on GitHub (pinned to 81dcd7d73e)
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
Example fix
// before: reading raw bytes without validation
v, err := asInt64(raw, 0)
// after: guard length before decoding
if len(raw) != 0 && len(raw) != 8 {
return 0, fmt.Errorf("unexpected int size: %d", len(raw))
}
v, err := asInt64(raw, 0) Defensive patterns
Strategy: validation
Validate before calling
if len(raw) != 0 && len(raw) != 8 {
return fmt.Errorf("value not an 8-byte int64: %d bytes", len(raw))
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- varint: overflow
- ErrNoBucket
- ErrEmptyPath
- kv: data version is out of date. Run cayleyupgrade for your
- cannot decode indexes: %v
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/9a17e86dcc80b9db.
Report an issue: GitHub.