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.Token

View on GitHub (pinned to 187eb24962)

Solutions

  1. Pass a *string: var s string; err := reader.Scan(&s).
  2. For JSON files the jsonReader.Scan accepts any pointer via encoding/json — use ReadAll on a .json file if you need arbitrary types.
  3. 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

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


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/3ca4fe4093f5694e. Report an issue: GitHub.