{"record":{"id":"9b869455bc9518a0","repo":"alibaba/open-code-review","slug":"unmarshal-task-template-manifest-w","errorCode":null,"errorMessage":"unmarshal task_template manifest: %w","messagePattern":"unmarshal task_template manifest: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/template/template.go","lineNumber":223,"sourceCode":"\tif m == nil {\n\t\treturn nil, nil\n\t}\n\tconv, err := resolveConversation(*m)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", name, err)\n\t}\n\treturn &conv, nil\n}\n\n// LoadDefault parses the embedded task_template.json and resolves prompt file references.\nfunc LoadDefault() (*Template, error) {\n\tdata, err := templateFS.ReadFile(\"task_template.json\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read embedded task_template.json: %w\", err)\n\t}\n\tvar m templateManifest\n\tif err := json.Unmarshal(data, &m); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal task_template manifest: %w\", err)\n\t}\n\n\tvar tpl Template\n\ttpl.MaxTokens = m.MaxTokens\n\ttpl.MaxCompletionTokens = m.MaxCompletionTokens\n\ttpl.MaxToolRequestTimes = m.MaxToolRequestTimes\n\ttpl.PlanModeLineThreshold = m.PlanModeLineThreshold\n\ttpl.PlanModeGroupLineThreshold = m.PlanModeGroupLineThreshold\n\ttpl.GroupingMinFiles = m.GroupingMinFiles\n\ttpl.GroupingBundleLineThreshold = m.GroupingBundleLineThreshold\n\ttpl.MaxReviewRounds = m.MaxReviewRounds\n\n\tif tpl.MainTask, err = resolveConversation(m.MainTask); err != nil {\n\t\treturn nil, fmt.Errorf(\"MAIN_TASK: %w\", err)\n\t}\n\tif tpl.PlanTask, err = resolveOptionalConversation(m.PlanTask, \"PLAN_TASK\"); err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/template/template.go#L205-L241","documentation":"After reading task_template.json, LoadDefault unmarshals it into templateManifest. If the JSON is syntactically invalid or its shape does not match templateManifest fields, json.Unmarshal fails and the error is wrapped as 'unmarshal task_template manifest'. This indicates the embedded template manifest is malformed, which is a source-tree defect shipped into the binary.","triggerScenarios":"Calling LoadDefault() when the embedded task_template.json contains invalid JSON (syntax error, trailing comma, BOM) or has fields with types that cannot unmarshal into templateManifest (e.g. a string where a number is expected).","commonSituations":"Hand-editing the JSON and introducing a syntax error; a merge conflict marker left in the file; changing a manifest field type in Go without updating the JSON; a tool rewriting the file with wrong encoding (UTF-16/BOM).","solutions":["Run the JSON through a validator (jq . task_template.json or python -m json.tool) and fix the syntax error at the reported offset","Compare field names/types in task_template.json against the templateManifest struct tags (e.g. \"MAX_TOKENS\") and fix mismatches","Ensure the file is UTF-8 without BOM; re-save with correct encoding","Rebuild the binary after fixing — the embedded copy changes only at compile time"],"exampleFix":"// before (task_template.json)\n{\"MAX_TOKENS\": 4096, \"MAIN_TASK\": {\"messages\": [},]}\n// after\n{\"MAX_TOKENS\": 4096, \"MAIN_TASK\": {\"messages\": []}}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\"internal/config/template/task_template.json\"); err != nil { t.Fatal(\"manifest missing\") }\n// fail the build early on invalid JSON:\nout, err := exec.Command(\"go\", \"run\", \"./cmd\", \"validate-template\").CombinedOutput()\nif err != nil { t.Fatalf(\"task_template.json invalid: %s\", out) }","typeGuard":null,"tryCatchPattern":"tpl, err := template.LoadDefault()\nif err != nil {\n\tvar syntaxErr *json.SyntaxErr\n\tvar typeErr *json.UnmarshalTypeError\n\tswitch {\n\tcase errors.As(err, &syntaxErr):\n\t\treturn fmt.Errorf(\"task_template.json is not valid JSON: %w\", err)\n\tcase errors.As(err, &typeErr):\n\t\treturn fmt.Errorf(\"task_template.json field %s has wrong type: %w\", typeErr.Field, err)\n\t}\n\treturn err\n}","preventionTips":["Run a JSON linter over template manifests in CI","Keep manifest keys in sync with templateManifest struct tags; add a round-trip test","Save JSON as UTF-8 without BOM"],"tags":["go","json","unmarshal","config"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}