cayleygraph/cayley · error
db: failed to load data: %v
Error message
db: failed to load data: %v
What it means
This error wraps any failure that occurs while streaming quads from the reader into the destination quad writer during DecompressAndLoad. quad.CopyBatch failed partway through (malformed input data, read error, write error), so the load is aborted and the underlying error is reported with the 'db: failed to load data:' prefix. It is a wrapped error, so the root cause is in the %v portion.
Source
Thrown at internal/load.go:135
return qr, nil
}
// DecompressAndLoad will load or fetch a graph from the given path, decompress
// it, and then call the given load function to process the decompressed graph.
// If no loadFn is provided, db.Load is called.
func DecompressAndLoad(qw quad.WriteCloser, batch int, path, typ string) error {
if path == "" {
return nil
}
qr, err := QuadReaderFor(path, typ)
if err != nil {
return err
}
defer qr.Close()
_, err = quad.CopyBatch(&batchLogger{w: qw}, qr, batch)
if err != nil {
return fmt.Errorf("db: failed to load data: %v", err)
}
return qw.Close()
}
type batchLogger struct {
cnt int
w quad.Writer
}
func (w *batchLogger) WriteQuads(quads []quad.Quad) (int, error) {
n, err := w.w.WriteQuads(quads)
if clog.V(2) {
w.cnt += n
clog.Infof("Wrote %d quads.", w.cnt)
}
return n, err
}
View on GitHub (pinned to 81dcd7d73e)
Solutions
- Inspect the wrapped cause printed after 'db: failed to load data:' and fix that specific issue (bad line, I/O error, etc.).
- Validate the input file with a small parser (e.g. read it as nquads with a separate tool) to find the first malformed record.
- Re-export the data from the source to regenerate a complete, valid file.
- Check disk space and permissions on the target store directory.
Example fix
// before
_, err = quad.CopyBatch(&batchLogger{w: qw}, qr, batch)
if err != nil {
return fmt.Errorf("db: failed to load data: %v", err)
}
// after
_, err = quad.CopyBatch(&batchLogger{w: qw}, qr, batch)
if err != nil {
return fmt.Errorf("db: failed to load data: %w", err) // unwrap with errors.Is/As upstream
} Defensive patterns
Strategy: try-catch
Try / catch
if _, err := internal.Load(...); err != nil {
var cause error
if strings.HasPrefix(err.Error(), "db: failed to load data:") {
cause = errors.Unwrap(err) // pre-errors-wrapping code: parse the %v suffix
}
log.Fatalf("load failed: %v", err)
}
Prevention
- Validate input files (line counts, first lines parse in the declared format) before a big import.
- Use errors.Unwrap/%w by patching the loader to preserve the root cause for programmatic handling.
- Monitor disk space and write permissions on the store directory before running imports.
- Load in small batches first to catch malformed records early.
When it happens
Trigger: Calling internal.DecompressAndLoad (via internal.Load / `cayley load`) where quad.CopyBatch returns an error: the input file contains invalid records for the chosen format, the reader hits an I/O error, or the destination writer fails.
Common situations: Loading a truncated or corrupted .nq file; a file whose contents don't actually match its declared format; disk-full or permission problems while writing into the store; a non-UTF8 or binary file mislabeled as nquads.
Related errors
- unknown quad format %q
- decoding of %q is not supported
- cannot count iterator without a valid context
- node tokens not valid
- varint: overflow
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/5133737d5c82b058.
Report an issue: GitHub.