{"record":{"id":"42a280defc3fa5d7","repo":"hashicorp/nomad","slug":"write-error-wrote-d-bytes-of-d-v","errorCode":null,"errorMessage":"write error, wrote %d bytes of %d: %v","messagePattern":"write error, wrote (.+?) bytes of (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":1555,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\n// writeNDJSON writes a single Nomad API objects (or response error) to the\n// archive file as a JSON object.\nfunc writeJSON(obj any, writer io.Writer) error {\n\tbuf, err := json.Marshal(obj)\n\tif err != nil {\n\t\tbuf, err = json.Marshal(errorWrapper{Error: err.Error()})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not serialize our own error: %v\", err)\n\t\t}\n\t}\n\tn, err := writer.Write(buf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"write error, wrote %d bytes of %d: %v\", n, len(buf), err)\n\t}\n\treturn nil\n}\n\n// writeNDJSON writes a slice of Nomad API objects to the archive file as\n// newline-delimited JSON objects.\nfunc writeNDJSON[T any](data []T, writer io.Writer) error {\n\tfor _, obj := range data {\n\t\terr := writeJSON(obj, writer)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write to file: %w\", err)\n\t\t}\n\t\t_, err = writer.Write([]byte{'\\n'})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write to file: %w\", err)\n\t\t}\n\t}\n","sourceCodeStart":1537,"sourceCodeEnd":1573,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L1537-L1573","documentation":"Returned by `writeJSON` when the write of the marshaled JSON bytes to the destination io.Writer (an archive file or stream writer) fails partway. It reports how many bytes were written versus the total, so you can tell whether the archive entry is truncated. The error is returned to the caller, which records it as a capture error in the bundle rather than aborting the whole debug run.","triggerScenarios":"writer.Write failing during capture output: disk full (ENOSPC), I/O error on the underlying file, or the writer being closed/consumed prematurely by an earlier failure in the capture pipeline.","commonSituations":"Debug bundle collection on a node whose disk filled mid-capture; writes to a filesystem that went read-only (disk remounted after error); interrupted network storage.","solutions":["Free space on the volume holding the capture directory — ENOSPC is the dominant cause.","Re-run the debug collection after resolving the disk/storage condition; affected archive entries will be truncated.","Target local disk rather than network storage for the -output directory.","Check system logs (dmesg, journald) for filesystem errors that may have remounted the disk read-only."],"exampleFix":"// before (shell)\nnomad operator debug -output /mnt/nfs/debug   # nfs dropped\n// after\nnomad operator debug -output /var/tmp/debug","handlingStrategy":"retry","validationCode":"if usage, err := diskusage(outDir); err == nil && usage.Free < estimatedBundleSize {\n    return fmt.Errorf(\"only %d bytes free on %s\", usage.Free, outDir)\n}","typeGuard":null,"tryCatchPattern":"if err := writeJSON(obj, w); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC) {\n        // free space or relocate output, then re-run the capture\n    }\n    return err\n}","preventionTips":["Enforce a free-space threshold before starting debug bundle collection.","Write bundles to local disk, not network filesystems.","Set up disk usage alerts on capture nodes.","Re-run the debug command after a write failure — partial entries will be truncated otherwise."],"tags":["filesystem","io","disk-full","json","debug"],"backgroundTag":"disk-full-write-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}