{"record":{"id":"a7466a10bed60d68","repo":"gastownhall/beads","slug":"parse-s-w","errorCode":null,"errorMessage":"parse %s: %w","messagePattern":"parse (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/formula/parser.go","lineNumber":146,"sourceCode":"\t\treturn cached, nil\n\t}\n\n\t// Read and parse the file\n\t// #nosec G304 -- absPath comes from controlled search paths or explicit user input\n\tdata, err := os.ReadFile(absPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read %s: %w\", path, err)\n\t}\n\n\t// Detect format from extension\n\tvar formula *Formula\n\tif strings.HasSuffix(path, FormulaExtTOML) {\n\t\tformula, err = p.ParseTOML(data)\n\t} else {\n\t\tformula, err = p.Parse(data)\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse %s: %w\", path, err)\n\t}\n\n\tformula.Source = absPath\n\n\t// Set source tracing info on all steps (gt-8tmz.18)\n\tSetSourceInfo(formula)\n\n\tp.cache[absPath] = formula\n\n\t// Also cache by name for extends resolution\n\tp.cache[formula.Formula] = formula\n\n\treturn formula, nil\n}\n\n// Parse parses a formula from JSON bytes.\nfunc (p *Parser) Parse(data []byte) (*Formula, error) {\n\tvar formula Formula","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/formula/parser.go#L128-L164","documentation":"The formula file was read successfully but failed to parse (JSON or TOML depending on extension); the parse error is wrapped as \"parse <path>: ...\". This means the file content is not valid for its declared format or doesn't unmarshal into the Formula struct.","triggerScenarios":"ParseFile dispatches to ParseTOML for *.formula.toml or Parse otherwise, and the unmarshaler rejects the bytes — syntax errors, wrong types (string where int expected), unknown structures.","commonSituations":"Hand-edited TOML with a missing quote/bracket; JSON with trailing commas; a `version` field written as a string; merge conflicts left markup in the file; file saved with the wrong extension.","solutions":["Read the inner parse error's line/column and fix the syntax at that location in the formula file.","Validate the file with a TOML/JSON linter or by running it through the parser in a test.","Ensure field types match the Formula struct (e.g. numeric version, array-of-tables for steps/template).","Restore the file from git if a merge/edit corrupted it."],"exampleFix":"// before (TOML)\nformula = \"scaffolding\ntype = \"expansion\"   # missing closing quote above\n// after\nformula = \"scaffolding\"\ntype = \"expansion\"","handlingStrategy":"try-catch","validationCode":"// syntax-check before handing bytes to the parser\nif strings.HasSuffix(path, \".formula.toml\") {\n\tif err := validateTOML(data); err != nil {\n\t\treturn fmt.Errorf(\"%s: invalid TOML: %w\", path, err)\n\t}\n} else if !json.Valid(data) {\n\treturn fmt.Errorf(\"%s: invalid JSON\", path)\n}","typeGuard":null,"tryCatchPattern":"f, err := parser.ParseFile(path)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"parse \"+path) {\n\t\treturn nil, fmt.Errorf(\"formula file %s is malformed (see wrapped error for line/col)\", path)\n\t}\n\treturn nil, err\n}","preventionTips":["Validate edited formula files with a TOML/JSON linter before committing.","Keep extensions truthful: TOML content must be .formula.toml, JSON content .formula.json.","Check `git diff` for merge-conflict markers in formula files."],"tags":["go","formula","toml","json","parse-error"],"backgroundTag":"formula-parse-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}