{"record":{"id":"3ca4fe4093f5694e","repo":"gofr-dev/gofr","slug":"input-should-be-a-pointer-to-a-string-3ca4fe","errorCode":null,"errorMessage":"input should be a pointer to a string","messagePattern":"input should be a pointer to a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/s3/file_parse.go","lineNumber":21,"sourceCode":"import (\n\t\"bufio\"\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"io\"\n\t\"os\"\n\t\"path\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go-v2/aws\"\n\tfile \"gofr.dev/pkg/gofr/datasource/file\"\n)\n\nvar (\n\t// errNotPointer is returned when Read method is called with a non-pointer argument.\n\terrStringNotPointer = errors.New(\"input should be a pointer to a string\")\n\tErrOutOfRange       = errors.New(\"out of range\")\n)\n\nconst (\n\tstatusErr     = \"ERROR\"\n\tstatusSuccess = \"SUCCESS\"\n)\n\n// textReader implements RowReader for reading text files.\ntype textReader struct {\n\tscanner *bufio.Scanner\n\tlogger  Logger\n}\n\n// jsonReader implements RowReader for reading JSON files.\ntype jsonReader struct {\n\tdecoder *json.Decoder\n\ttoken   json.Token","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/s3/file_parse.go#L3-L39","documentation":"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.","triggerScenarios":"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{}).","commonSituations":"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.","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."],"exampleFix":"// before\nvar n int\nreader.Scan(&n) // errStringNotPointer\n// after\nvar s string\nerr := reader.Scan(&s)","handlingStrategy":"type-guard","validationCode":"var line string\nif err := reader.Scan(&line); err != nil {\n    // includes errStringNotPointer when arg is not *string\n    return err\n}","typeGuard":"func isStringPtr(i any) bool { _, ok := i.(*string); return ok }","tryCatchPattern":"err := reader.Scan(arg)\nif err != nil && strings.Contains(err.Error(), \"pointer to a string\") {\n    return fmt.Errorf(\"Scan needs *string, got %T\", arg)\n}","preventionTips":["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."],"tags":["type-mismatch","scan","rowreader","gofr"],"backgroundTag":"argument-type-mismatch","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}