{"record":{"id":"a711152751e4100d","repo":"JuliusBrussee/caveman","slug":"gzip-w","errorCode":null,"errorMessage":"gzip: %w","messagePattern":"gzip: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/objectstore/compress.go","lineNumber":43,"sourceCode":"\t// expand beyond the caller's plaintext ceiling.\n\tErrDecompressedTooLarge = errors.New(\"objectstore: decompressed payload exceeds limit\")\n)\n\n// DefaultMaxDecompressedBytes protects callers that do not have trusted size\n// metadata. Callers with an expected plaintext size should use\n// DecompressLimit with the smaller, metadata-validated limit.\nconst DefaultMaxDecompressedBytes int64 = 128 << 20\n\n// Compress encodes data with the named codec. \"none\" returns data unchanged.\nfunc Compress(codec string, data []byte) ([]byte, error) {\n\tswitch codec {\n\tcase CompressionNone, \"\":\n\t\treturn data, nil\n\tcase CompressionGzip:\n\t\tvar buf bytes.Buffer\n\t\tzw := gzip.NewWriter(&buf)\n\t\tif _, err := zw.Write(data); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"gzip: %w\", err)\n\t\t}\n\t\tif err := zw.Close(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"gzip close: %w\", err)\n\t\t}\n\t\treturn buf.Bytes(), nil\n\tcase CompressionZstd:\n\t\treturn zstdEnc.EncodeAll(data, nil), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown compression codec %q\", codec)\n\t}\n}\n\n// Decompress reverses Compress with a defensive default expansion ceiling. An\n// unknown codec fails closed.\nfunc Decompress(codec string, data []byte) ([]byte, error) {\n\treturn DecompressLimit(codec, data, DefaultMaxDecompressedBytes)\n}\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/objectstore/compress.go#L25-L61","documentation":"Compress failed while writing input data into a gzip.Writer backed by an in-memory buffer. gzip's Write only errors if the underlying writer fails or internal state is corrupted, which for a bytes.Buffer is essentially impossible in normal use; seeing this indicates a corrupted compressor or an out-of-memory/panic-like condition surfaced as an error. It is wrapped with the \"gzip: \" prefix and returned with a nil result.","triggerScenarios":"Calling objectstore.Compress with codec CompressionGzip where zw.Write(data) returns a non-nil error — realistically only from a corrupted gzip.Writer state, exotic Writer wrappers, or resource exhaustion.","commonSituations":"Very rare in practice because bytes.Buffer never fails; may appear in tests with injected failure writers, or after refactors that swap the buffer for a failing io.Writer.","solutions":["Retry the compression call — a one-off write failure on an in-memory buffer is not reproducible.","Inspect the wrapped error to identify the real cause; if it persists, check for corrupted binary/dependency versions.","Ensure you are passing a valid []byte to Compress (nil is fine; it means empty input).","If this recurs in tests, check whether a custom io.Writer is being injected that can fail.","Keep the compressed-data path simple: pass data directly to Compress rather than wrapping writers yourself."],"exampleFix":"// before\nout, err := objectstore.Compress(objectstore.CompressionGzip, data) // gzip: write failed\n// after\nout, err := objectstore.Compress(objectstore.CompressionGzip, data)\nif err != nil {\n    return fmt.Errorf(\"compressing object before upload: %w\", err) // add context for diagnosis\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := objectstore.Compress(codec, data)\nif err != nil {\n    // gzip write failures on an in-memory buffer are effectively non-reproducible:\n    // log and retry once, then surface the wrapped cause\n    out, err = objectstore.Compress(codec, data)\n    if err != nil {\n        return fmt.Errorf(\"compression failed: %w\", err)\n    }\n}","preventionTips":["Pass data directly to Compress; do not inject custom failing writers.","Pin library/dependency versions to avoid corrupted builds.","Retry once on transient write failures before surfacing the error.","Monitor process memory if compressing very large inputs."],"tags":["compression","gzip","go","objectstore"],"backgroundTag":"gzip-compression-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}