gofr-dev/gofr · error
input should be a pointer to a string
Error message
input should be a pointer to a string
What it means
errStringNotPointer is returned by textReader.Scan when the argument passed is not a *string. The text/CSV row reader can only scan a line into a string pointer, and it performs a type assertion instead of silently failing later. It is unexported, so callers should just match on the error message or wrap with a generic check.
Source
Thrown at pkg/gofr/datasource/file/s3/file_parse.go:21
import (
"bufio"
"bytes"
"encoding/json"
"errors"
"io"
"os"
"path"
"path/filepath"
"strings"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
file "gofr.dev/pkg/gofr/datasource/file"
)
var (
// errNotPointer is returned when Read method is called with a non-pointer argument.
errStringNotPointer = errors.New("input should be a pointer to a string")
ErrOutOfRange = errors.New("out of range")
)
const (
statusErr = "ERROR"
statusSuccess = "SUCCESS"
)
// textReader implements RowReader for reading text files.
type textReader struct {
scanner *bufio.Scanner
logger Logger
}
// jsonReader implements RowReader for reading JSON files.
type jsonReader struct {
decoder *json.Decoder
token json.TokenView on GitHub (pinned to 187eb24962)
Solutions
- Pass a *string: var s string; err := reader.Scan(&s).
- For JSON files the jsonReader.Scan accepts any pointer via encoding/json — use ReadAll on a .json file if you need arbitrary types.
- Adjust generic scanning loops to always allocate a string per row.
Example fix
// before var n int reader.Scan(&n) // errStringNotPointer // after var s string err := reader.Scan(&s)
Defensive patterns
Strategy: type-guard
Validate before calling
var line string
if err := reader.Scan(&line); err != nil {
// includes errStringNotPointer when arg is not *string
return err
} Type guard
func isStringPtr(i any) bool { _, ok := i.(*string); return ok } Try / catch
err := reader.Scan(arg)
if err != nil && strings.Contains(err.Error(), "pointer to a string") {
return fmt.Errorf("Scan needs *string, got %T", arg)
} Prevention
- Always pass &someString to textReader.Scan.
- Remember this RowReader is line-oriented: only *string for text/CSV files.
- Use .json files with jsonReader.Scan for structured types.
- Keep row loops typed consistently.
When it happens
Trigger: Calling Scan on the RowReader obtained from ReadAll() for a text/CSV file with any non-*string argument, e.g. Scan(&myInt), Scan(myString) (value, not pointer), or Scan(&struct{}).
Common situations: Generic row-processing code assuming Scan accepts any type (unlike database/sql's variadic Scan); passing values instead of pointers; copying the database/sql *[]byte habit into this API.
Related errors
- operations cannot be empty
- elasticsearch operation error
- errFileNotOpenForReading
- response retrieved is nil
- s3 backend did not honor the requested byte range
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/3ca4fe4093f5694e.
Report an issue: GitHub.