{"record":{"id":"d39d924c2751ab4b","repo":"ent/ent","slug":"graphson-rawmessage-unmarshalgraphson-on-nil-poin","errorCode":null,"errorMessage":"graphson.RawMessage: UnmarshalGraphson on nil pointer","messagePattern":"graphson\\.RawMessage: UnmarshalGraphson on nil pointer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dialect/gremlin/encoding/graphson/raw.go","lineNumber":31,"sourceCode":"\n// RawMessage must implement Marshaler/Unmarshaler interfaces.\nvar (\n\t_ Marshaler   = (*RawMessage)(nil)\n\t_ Unmarshaler = (*RawMessage)(nil)\n)\n\n// MarshalGraphson returns m as the graphson encoding of m.\nfunc (m RawMessage) MarshalGraphson() ([]byte, error) {\n\tif m == nil {\n\t\treturn []byte(\"null\"), nil\n\t}\n\treturn m, nil\n}\n\n// UnmarshalGraphson sets *m to a copy of data.\nfunc (m *RawMessage) UnmarshalGraphson(data []byte) error {\n\tif m == nil {\n\t\treturn errors.New(\"graphson.RawMessage: UnmarshalGraphson on nil pointer\")\n\t}\n\t*m = append((*m)[0:0], data...)\n\treturn nil\n}\n","sourceCodeStart":13,"sourceCodeEnd":36,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/dialect/gremlin/encoding/graphson/raw.go#L13-L36","documentation":"UnmarshalGraphson is defined on a *RawMessage, and Go allows calling methods through a nil pointer receiver. This guard fires when the method is invoked on a nil *RawMessage, i.e. the caller never allocated the RawMessage (or holds a nil interface/pointer) before asking it to absorb the decoded bytes. The offending input is the nil receiver m, not the data argument.","triggerScenarios":"Declaring `var m *graphson.RawMessage` (nil pointer) and calling `m.UnmarshalGraphson(data)`; having a struct field of type *RawMessage left nil when the decoder calls into it.","commonSituations":"Using a pointer-to-pointer or nil struct field in a response type; forgetting to initialize a RawMessage field before decoding.","solutions":["Initialize the value: `m := graphson.RawMessage{}` and call on the addressable value, or `m = &graphson.RawMessage{}`","Use a non-pointer `graphson.RawMessage` field/type in your target struct"],"exampleFix":"// before\nvar m *graphson.RawMessage\nm.UnmarshalGraphson(data)\n// after\nm := &graphson.RawMessage{}\nm.UnmarshalGraphson(data)","handlingStrategy":"type-guard","validationCode":"if m == nil { return errors.New(\"RawMessage receiver must be initialized\") }","typeGuard":"func safeUnmarshal(m *graphson.RawMessage, data []byte) error {\n  if m == nil { m = &graphson.RawMessage{} }\n  return m.UnmarshalGraphson(data)\n}","tryCatchPattern":"if err := m.UnmarshalGraphson(data); err != nil {\n  return fmt.Errorf(\"raw graphson: %w\", err)\n}","preventionTips":["Use value type graphson.RawMessage, not *RawMessage, in structs","Initialize pointer fields before decoding","Never call UnmarshalGraphson on a freshly declared nil pointer"],"tags":["gremlin","graphson","nil-pointer","decoding"],"backgroundTag":"unmarshal-nil-pointer","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}