gofiber/fiber · error
only file paths and io.Writer are supported
Error message
only file paths and io.Writer are supported
What it means
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.
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.
Example fix
// before
var p int
err := resp.Save(&p) // ErrNotSupportSaveMethod
// after
f, _ := os.Create("body.bin")
defer f.Close()
err := resp.Save(f) Defensive patterns
Strategy: type-guard
Validate before calling
func isValidSaveDest(v any) bool {
switch v.(type) {
case string:
return true
case io.Writer:
return true
}
return false
} Type guard
func isStringOrWriter(v any) bool {
if _, ok := v.(string); ok { return true }
if _, ok := v.(io.Writer); ok { return true }
return false
} Try / catch
if err := resp.Save(dest); err != nil {
if errors.Is(err, fiber.ErrNotSupportSaveMethod) {
// open a file or use bytes.Buffer and retry
}
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- failed to write response body to file
- failed to write response body to writer
- the file should have a name
- client cannot be nil
- client: HTTPS to HTTP redirect blocked
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/dbd48676f4010e50.
Report an issue: GitHub.
Appendix: source
Thrown at client/core.go:305
// - the channel is not closed
// - the channel is drained before returning it
// - the channel is not reused after returning it
func releaseErrChan(ch chan error) {
errChanPool.Put(ch)
}
// newCore returns a new core object.
func newCore() *core {
return &core{}
}
var (
ErrTimeoutOrCancel = errors.New("timeout or cancel")
ErrURLFormat = errors.New("the URL is incorrect")
ErrNotSupportSchema = errors.New("protocol not supported; only http or https are allowed")
ErrFileNoName = errors.New("the file should have a name")
ErrBodyType = errors.New("the body type should be []byte")
ErrNotSupportSaveMethod = errors.New("only file paths and io.Writer are supported")
ErrBodyTypeNotSupported = errors.New("the body type is not supported")
)
View on GitHub (pinned to a105acad6c)