{"record":{"id":"57298811caa6372f","repo":"nats-io/nats-server","slug":"can-not-marshal-v-572988","errorCode":null,"errorMessage":"can not marshal %v","messagePattern":"can not marshal (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":227,"sourceCode":"func (wc PersistModeType) String() string {\n\tswitch wc {\n\tcase DefaultPersistMode:\n\t\treturn \"Default\"\n\tcase AsyncPersistMode:\n\t\treturn \"Async\"\n\tdefault:\n\t\treturn \"Unknown Persist Mode Type\"\n\t}\n}\n\nfunc (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\"`","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L209-L245","documentation":"PersistModeType.MarshalJSON returns this error when the PersistMode value being serialized is not DefaultPersistMode or AsyncPersistMode — i.e. the in-memory enum holds an out-of-range value. This surfaces when marshaling a stream config that carries a corrupted or uninitialized PersistMode.","triggerScenarios":"json.Marshal on a StreamConfig whose PersistMode field was set to an out-of-range value (e.g. constructed via an unchecked cast or zero-value outside the known constants).","commonSituations":"Custom tooling that builds StreamConfig structs programmatically, or older binaries writing configs consumed as raw ints.","solutions":["Set PersistMode only via the defined constants: DefaultPersistMode or AsyncPersistMode.","Check for casts/assignments that put an arbitrary integer into the PersistMode field.","If async persistence is intended, set the field explicitly to AsyncPersistMode; otherwise leave it DefaultPersistMode."],"exampleFix":"// before\ncfg := StreamConfig{PersistMode: PersistModeType(7)}\n// after\ncfg := StreamConfig{PersistMode: AsyncPersistMode}","handlingStrategy":"validation","validationCode":"if wc := cfg.PersistMode; wc != DefaultPersistMode && wc != AsyncPersistMode {\n  return fmt.Errorf(\"invalid persist mode %v\", wc)\n}","typeGuard":"func isPersistMode(w PersistModeType) bool {\n  return w == DefaultPersistMode || w == AsyncPersistMode\n}","tryCatchPattern":null,"preventionTips":["Only assign PersistMode from package constants.","Never cast arbitrary integers into PersistModeType."],"tags":["json","jetstream","marshal","persist-mode"],"backgroundTag":"json-marshal-invalid-enum","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}