{"record":{"id":"5133737d5c82b058","repo":"cayleygraph/cayley","slug":"db-failed-to-load-data-v","errorCode":null,"errorMessage":"db: failed to load data: %v","messagePattern":"db: failed to load data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/load.go","lineNumber":135,"sourceCode":"\treturn qr, nil\n}\n\n// DecompressAndLoad will load or fetch a graph from the given path, decompress\n// it, and then call the given load function to process the decompressed graph.\n// If no loadFn is provided, db.Load is called.\nfunc DecompressAndLoad(qw quad.WriteCloser, batch int, path, typ string) error {\n\tif path == \"\" {\n\t\treturn nil\n\t}\n\tqr, err := QuadReaderFor(path, typ)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer qr.Close()\n\n\t_, err = quad.CopyBatch(&batchLogger{w: qw}, qr, batch)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"db: failed to load data: %v\", err)\n\t}\n\treturn qw.Close()\n}\n\ntype batchLogger struct {\n\tcnt int\n\tw   quad.Writer\n}\n\nfunc (w *batchLogger) WriteQuads(quads []quad.Quad) (int, error) {\n\tn, err := w.w.WriteQuads(quads)\n\tif clog.V(2) {\n\t\tw.cnt += n\n\t\tclog.Infof(\"Wrote %d quads.\", w.cnt)\n\t}\n\treturn n, err\n}\n","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/internal/load.go#L117-L153","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n_, err = quad.CopyBatch(&batchLogger{w: qw}, qr, batch)\nif err != nil {\n\treturn fmt.Errorf(\"db: failed to load data: %v\", err)\n}\n// after\n_, err = quad.CopyBatch(&batchLogger{w: qw}, qr, batch)\nif err != nil {\n\treturn fmt.Errorf(\"db: failed to load data: %w\", err) // unwrap with errors.Is/As upstream\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := internal.Load(...); err != nil {\n\tvar cause error\n\tif strings.HasPrefix(err.Error(), \"db: failed to load data:\") {\n\t\tcause = errors.Unwrap(err) // pre-errors-wrapping code: parse the %v suffix\n\t}\n\tlog.Fatalf(\"load failed: %v\", err)\n}\n","preventionTips":["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."],"tags":["go","loading","error-wrapping","data-import"],"backgroundTag":"database-write-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"}