{"record":{"id":"330d74099a46e1af","repo":"jmoiron/sqlx","slug":"incompatible-type-for-gzippedtext","errorCode":null,"errorMessage":"Incompatible type for GzippedText","messagePattern":"Incompatible type for GzippedText","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/types.go","lineNumber":39,"sourceCode":"\tw := gzip.NewWriter(buf)\n\tw.Write(g)\n\tw.Close()\n\treturn buf.Bytes(), nil\n\n}\n\n// Scan implements the sql.Scanner interface, ungzipping the value coming off\n// the wire and storing the raw result in the GzippedText.\nfunc (g *GzippedText) Scan(src interface{}) error {\n\tvar source []byte\n\tswitch src := src.(type) {\n\tcase string:\n\t\tsource = []byte(src)\n\tcase []byte:\n\t\tsource = src\n\tdefault:\n\t\t//lint:ignore ST1005 changing this could break consumers of this package\n\t\treturn errors.New(\"Incompatible type for GzippedText\")\n\t}\n\treader, err := gzip.NewReader(bytes.NewReader(source))\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer reader.Close()\n\tb, err := ioutil.ReadAll(reader)\n\tif err != nil {\n\t\treturn err\n\t}\n\t*g = GzippedText(b)\n\treturn nil\n}\n\n// JSONText is a json.RawMessage, which is a []byte underneath.\n// Value() validates the json format in the source, and returns an error if\n// the json is not valid.  Scan does no validation.  JSONText additionally\n// implements `Unmarshal`, which unmarshals the json within to an interface{}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jmoiron/sqlx/blob/41dac167fdad5e3fd81d66cafba0951dc6823a30/types/types.go#L21-L57","documentation":"GzippedText.Scan implements sql.Scanner and accepts only string or []byte source values (the raw gzipped bytes from the DB). Any other driver-returned type cannot be interpreted as gzip input, so Scan returns this error. The error text is capitalized because changing it would break consumers (see lint ignore).","triggerScenarios":"Scanning a GzippedText column where the driver returns a non-string/non-[]byte value, e.g. an int64/float64 (numeric column) or time.Time, into a GzippedText field.","commonSituations":"Column declared as an integer/BLOB-adjacent type or the driver encodes blobs differently (e.g. some drivers return string, others []byte); using a driver that returns custom types; pointing GzippedText at a non-gzip column.","solutions":["Ensure the DB column stores gzipped data as a binary/text type the driver returns as []byte or string.","If the driver returns another type, scan into a []byte first and set GzippedText via its Set method.","Check driver behavior/version for how BLOB/TEXT values are returned.","If the data is not actually gzip, use plain Text/JSONText instead."],"exampleFix":"// before\nvar g types.GzippedText\nrow.Scan(&g) // driver returns float64\n// after\nvar raw []byte\nrow.Scan(&raw)\ng.Set(raw)","handlingStrategy":"type-guard","validationCode":"func gzippable(src interface{}) bool {\n\tswitch src.(type) {\n\tcase []byte, string, nil:\n\t\treturn true\n\tdefault:\n\t\treturn false\n\t}\n}","typeGuard":"func isByteLike(v interface{}) bool {\n\tswitch v.(type) {\n\tcase []byte, string:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"var g types.GzippedText\nif err := row.Scan(&g); err != nil {\n\tif err.Error() == \"Incompatible type for GzippedText\" {\n\t\t// inspect database/sql's returned type via reflect.TypeOf\n\t}\n\treturn err\n}","preventionTips":["Only use GzippedText on columns the driver returns as []byte/string.","Verify driver behavior with a small test row before production.","Scan into []byte manually when the driver type is uncertain.","Confirm column content is valid gzip before decompression."],"tags":["sql","scan","gzip","type-mismatch"],"backgroundTag":"scanner-incompatible-type","analyzedSha":"41dac167fdad5e3fd81d66cafba0951dc6823a30","analyzedAt":"2026-09-03T06:10:20.382Z","contentChangedAt":"2026-09-03T06:10:20.382Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}