{"record":{"id":"61b1516e3949e2c0","repo":"gastownhall/beads","slug":"failed-to-marshal-issue-s-w","errorCode":null,"errorMessage":"failed to marshal issue %s: %w","messagePattern":"failed to marshal issue (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/detect_pollution.go","lineNumber":112,"sourceCode":"\t}\n\n\treturn results\n}\n\nfunc backupPollutedIssues(polluted []pollutionResult, path string) error {\n\t// Create backup file\n\t// nolint:gosec // G304: path is provided by user as explicit backup location\n\tfile, err := os.Create(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create backup file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\t// Write each issue as JSONL\n\tfor _, p := range polluted {\n\t\tdata, err := json.Marshal(p.issue)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to marshal issue %s: %w\", p.issue.ID, err)\n\t\t}\n\n\t\tif _, err := file.WriteString(string(data) + \"\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write issue %s: %w\", p.issue.ID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":94,"sourceCodeEnd":122,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/detect_pollution.go#L94-L122","documentation":"While writing the backup, each polluted issue is serialized with json.Marshal before being appended as a JSONL line. If marshaling a particular issue fails, backupPollutedIssues returns this error naming the issue ID. With standard issue structs this is rare and usually indicates an unsupported value embedded in the issue (e.g. a channel, func, or cyclic field).","triggerScenarios":"os.Create succeeded but json.Marshal(p.issue) returns an error for a specific issue — typically a corrupted or non-serializable field in the stored issue data, or a struct field type unsupported by encoding/json.","commonSituations":"Database contains an issue written by an older/incompatible schema whose fields no longer marshal; custom field values inserted directly into storage; third-party types lacking MarshalJSON injected into the issue struct.","solutions":["Identify the offending issue ID from the message and inspect it with 'bd show <id>' or direct DB access.","Fix or remove the malformed issue so it can be serialized (edit and re-save it).","Check for schema/version mismatch between the bd binary and the database; upgrade or run migration.","If caused by a code change to types.Issue, add a MarshalJSON or json tag fix for the unsupported field."],"exampleFix":"// before: unsupported field\nCustom chan int `json:\"custom\"`\n// after: remove or give it a JSON-safe representation\nCustom string `json:\"custom,omitempty\"`","handlingStrategy":"validation","validationCode":"// probe-serialize issues before committing to the backup run\nfor _, p := range polluted {\n    if _, err := json.Marshal(p.issue); err != nil {\n        fmt.Printf(\"issue %s will fail backup: %v\\n\", p.issue.ID, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := json.Marshal(p.issue); err != nil {\n    log.Printf(\"skipping unmarshalable issue %s: %v\", p.issue.ID, err)\n    continue\n}","preventionTips":["Keep types.Issue fields JSON-serializable (no chan/func/cyclic fields).","Add json tags to all exported struct fields.","Fix or quarantine malformed issues flagged by doctor before backup.","Keep the bd binary and database schema versions aligned."],"tags":["go","json","serialization","backup"],"backgroundTag":"json-marshal-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}