{"record":{"id":"07565381cad90d9c","repo":"BoundaryML/baml","slug":"invalid-streamstatetype-q","errorCode":null,"errorMessage":"invalid StreamStateType: %q","messagePattern":"invalid StreamStateType: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/shared/stream_state.go","lineNumber":40,"sourceCode":"\t}\n}\n\n// IsValid checks whether the given AliasedEnum value is valid.\nfunc (e StreamStateType) IsValid() bool {\n\n\tfor _, v := range e.Values() {\n\t\tif e == v {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n\n}\n\n// MarshalJSON customizes JSON marshaling for AliasedEnum.\nfunc (e StreamStateType) MarshalJSON() ([]byte, error) {\n\tif !e.IsValid() {\n\t\treturn nil, fmt.Errorf(\"invalid StreamStateType: %q\", e)\n\t}\n\treturn json.Marshal(string(e))\n}\n\n// UnmarshalJSON customizes JSON unmarshaling for AliasedEnum.\nfunc (e *StreamStateType) UnmarshalJSON(data []byte) error {\n\tvar s string\n\tif err := json.Unmarshal(data, &s); err != nil {\n\t\treturn err\n\t}\n\t*e = StreamStateType(s)\n\tif !e.IsValid() {\n\t\treturn fmt.Errorf(\"invalid StreamStateType: %q\", s)\n\t}\n\treturn nil\n}\n\ntype StreamState[T any] struct {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/shared/stream_state.go#L22-L58","documentation":"StreamStateType is an aliased string enum; MarshalJSON validates the value before serializing. If the StreamStateType value was constructed from an arbitrary string that is not one of the defined constants, marshaling fails with this error instead of emitting an invalid enum value into JSON.","triggerScenarios":"Creating a StreamStateType via a raw conversion like StreamStateType(\"runnning\") (typo) or reading it from external data without UnmarshalJSON validation, then calling json.Marshal on a struct containing it.","commonSituations":"Hand-written stream state strings, values loaded from config or another service with different enum spellings, or zero-value StreamStateType(\"\") accidentally left unset before marshaling.","solutions":["Print/log the value and compare against the defined StreamStateType constants; fix the spelling/value.","Use the exported constants instead of raw string conversions.","Populate the field via json.Unmarshal (which validates) or a constructor that calls IsValid().","Check for the zero value (\"\") when a struct containing StreamStateType is created without initialization."],"exampleFix":"// before\nstate := shared.StreamStateType(\"comlete\")\ndata, _ := json.Marshal(state) // error\n\n// after\nstate := shared.StreamStateRunning // use defined constant\ndata, _ := json.Marshal(state)","handlingStrategy":"type-guard","validationCode":"func validStreamStateType(s string) bool {\n\treturn shared.StreamStateType(s).IsValid()\n}","typeGuard":"func asStreamStateType(s string) (shared.StreamStateType, bool) {\n\tt := shared.StreamStateType(s)\n\treturn t, t.IsValid()\n}","tryCatchPattern":"data, err := json.Marshal(state)\nif err != nil {\n\tvar inv *json.UnsupportedTypeError\n\t_ = errors.As(err, &inv)\n\treturn fmt.Errorf(\"stream state %q invalid: %w\", state, err)\n}","preventionTips":["Always use exported StreamStateType constants","Never convert raw strings to StreamStateType without IsValid()","Initialize structs containing StreamStateType explicitly"],"tags":["go","json","enum","marshaling"],"backgroundTag":"invalid-enum-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}