{"record":{"id":"dbd48676f4010e50","repo":"gofiber/fiber","slug":"only-file-paths-and-io-writer-are-supported","errorCode":null,"errorMessage":"only file paths and io.Writer are supported","messagePattern":"only file paths and io\\.Writer are supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/core.go","lineNumber":305,"sourceCode":"// - the channel is not closed\n// - the channel is drained before returning it\n// - the channel is not reused after returning it\nfunc releaseErrChan(ch chan error) {\n\terrChanPool.Put(ch)\n}\n\n// newCore returns a new core object.\nfunc newCore() *core {\n\treturn &core{}\n}\n\nvar (\n\tErrTimeoutOrCancel      = errors.New(\"timeout or cancel\")\n\tErrURLFormat            = errors.New(\"the URL is incorrect\")\n\tErrNotSupportSchema     = errors.New(\"protocol not supported; only http or https are allowed\")\n\tErrFileNoName           = errors.New(\"the file should have a name\")\n\tErrBodyType             = errors.New(\"the body type should be []byte\")\n\tErrNotSupportSaveMethod = errors.New(\"only file paths and io.Writer are supported\")\n\tErrBodyTypeNotSupported = errors.New(\"the body type is not supported\")\n)\n","sourceCodeStart":287,"sourceCodeEnd":308,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/client/core.go#L287-L308","documentation":"Returned by Response.Save (client/response.go:230) when its argument is neither a string (file path) nor an io.Writer. Save's switch only handles those two destination kinds; any other type (int, struct, *os.File with nil, map) hits the default branch.","triggerScenarios":"Calling resp.Save(someStruct), resp.Save(123), resp.Save(nil), or passing a channel/pointer-to-non-writer. Also passing an *os.File that is nil (it is not io.Writer in the nil-pointer case for the type switch).","commonSituations":"Refactoring Save to write to a buffer but passing *bytes.Buffer correctly works (it is io.Writer); passing the underlying byte slice instead of the buffer; passing a path object from a third-party package that isn't a plain string; nil receivers.","solutions":["Pass a string path to write to a file: resp.Save(\"/tmp/out.bin\").","Pass an io.Writer (e.g. *os.File, *bytes.Buffer, *gzip.Writer) to stream the body: resp.Save(&buf).","For nil safety, check writers for nil before passing, especially *os.File.","If you have a custom Path type, call .String() to convert before Save."],"exampleFix":"// before\nvar p int\nerr := resp.Save(&p) // ErrNotSupportSaveMethod\n\n// after\nf, _ := os.Create(\"body.bin\")\ndefer f.Close()\nerr := resp.Save(f)","handlingStrategy":"type-guard","validationCode":"func isValidSaveDest(v any) bool {\n    switch v.(type) {\n    case string:\n        return true\n    case io.Writer:\n        return true\n    }\n    return false\n}","typeGuard":"func isStringOrWriter(v any) bool {\n    if _, ok := v.(string); ok { return true }\n    if _, ok := v.(io.Writer); ok { return true }\n    return false\n}","tryCatchPattern":"if err := resp.Save(dest); err != nil {\n    if errors.Is(err, fiber.ErrNotSupportSaveMethod) {\n        // open a file or use bytes.Buffer and retry\n    }\n}","preventionTips":["Pass either a string path or an io.Writer to Save.","For in-memory capture use *bytes.Buffer, not []byte.","Guard nil *os.File before passing it as a Writer."],"tags":["client","response","io","files","http"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}