{"record":{"id":"b323f5ecfc8f0da5","repo":"nats-io/nats-server","slug":"can-not-unmarshal-q-b323f5","errorCode":null,"errorMessage":"can not unmarshal %q","messagePattern":"can not unmarshal %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":238,"sourceCode":"func (wc PersistModeType) MarshalJSON() ([]byte, error) {\n\tswitch wc {\n\tcase DefaultPersistMode:\n\t\treturn defaultPersistModeJSONBytes, nil\n\tcase AsyncPersistMode:\n\t\treturn asyncPersistModeJSONBytes, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"can not marshal %v\", wc)\n\t}\n}\n\nfunc (wc *PersistModeType) UnmarshalJSON(data []byte) error {\n\tswitch string(data) {\n\tcase defaultPersistModeJSONString, `\"\"`:\n\t\t*wc = DefaultPersistMode\n\tcase asyncPersistModeJSONString:\n\t\t*wc = AsyncPersistMode\n\tdefault:\n\t\treturn fmt.Errorf(\"can not unmarshal %q\", data)\n\t}\n\treturn nil\n}\n\n// JSPubAckResponse is a formal response to a publish operation.\ntype JSPubAckResponse struct {\n\tError *ApiError `json:\"error,omitempty\"`\n\t*PubAck\n}\n\n// ToError checks if the response has a error and if it does converts it to an error\n// avoiding the pitfalls described by https://yourbasic.org/golang/gotcha-why-nil-error-not-equal-nil/\nfunc (r *JSPubAckResponse) ToError() error {\n\tif r.Error == nil {\n\t\treturn nil\n\t}\n\treturn r.Error\n}","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L220-L256","documentation":"PersistModeType.UnmarshalJSON rejects JSON values that are neither the recognized persist-mode strings (e.g. \"default\", \"async\") nor an empty string. The stream config decode fails when persist_mode contains an unknown value.","triggerScenarios":"Decoding a StreamConfig whose persist_mode field is a typo, wrong case, or an arbitrary string not in the accepted set.","commonSituations":"Configs edited by hand, values copied from docs of a different version, or JSON produced by another system with different persist-mode naming.","solutions":["Use the exact accepted string (\"async\" for async persist; \"default\" or \"\" otherwise).","Remove the persist_mode field entirely to get the default mode.","Use a typed client constant rather than a hand-written string."],"exampleFix":"// before\n{\"persist_mode\": \"asyncronous\"}\n// after\n{\"persist_mode\": \"async\"}","handlingStrategy":"validation","validationCode":"pm := cfg.PersistMode\nif pm != \"async\" && pm != \"default\" && pm != \"\" { return fmt.Errorf(\"invalid persist_mode %q\", pm) }","typeGuard":"func isPersistModeString(s string) bool {\n  return s == \"async\" || s == \"default\" || s == \"\"\n}","tryCatchPattern":null,"preventionTips":["Prefer the typed PersistMode constants over raw strings.","Omit persist_mode to get the default."],"tags":["json","jetstream","unmarshal","persist-mode"],"backgroundTag":"json-unmarshal-invalid-enum","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}