{"record":{"id":"ca6c792bff9569c8","repo":"alibaba/open-code-review","slug":"unmarshal-default-scan-template-w","errorCode":null,"errorMessage":"unmarshal default scan template: %w","messagePattern":"unmarshal default scan template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/template/template.go","lineNumber":261,"sourceCode":"\t\treturn nil, fmt.Errorf(\"MEMORY_COMPRESSION_TASK: %w\", err)\n\t}\n\tif tpl.ReLocationTask, err = resolveOptionalConversation(m.ReLocationTask, \"RE_LOCATION_TASK\"); err != nil {\n\t\treturn nil, err\n\t}\n\tif tpl.ReviewFilterTask, err = resolveOptionalConversation(m.ReviewFilterTask, \"REVIEW_FILTER_TASK\"); err != nil {\n\t\treturn nil, err\n\t}\n\tif tpl.GroupingTask, err = resolveOptionalConversation(m.GroupingTask, \"GROUPING_TASK\"); err != nil {\n\t\treturn nil, err\n\t}\n\treturn &tpl, nil\n}\n\n// LoadScanDefault parses the embedded scan_template.json.\nfunc LoadScanDefault() (*ScanTemplate, error) {\n\tvar tpl ScanTemplate\n\tif err := json.Unmarshal(defaultScanTemplate, &tpl); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal default scan template: %w\", err)\n\t}\n\treturn &tpl, nil\n}\n\n// applyLanguage appends instruction to all system-role messages in conv.\nfunc applyLanguage(conv *LlmConversation, instruction string) {\n\tfor i := range conv.Messages {\n\t\tif conv.Messages[i].Role == \"system\" {\n\t\t\tconv.Messages[i].Content += instruction\n\t\t}\n\t}\n}\n\n// resolveLang returns the resolved language name for the instruction.\nfunc resolveLang(lang string) string {\n\tif lang == \"\" {\n\t\treturn \"English\"\n\t}","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/template/template.go#L243-L279","documentation":"LoadScanDefault unmarshals the embedded scan_template.json bytes (defaultScanTemplate) into ScanTemplate. If that JSON is invalid or incompatible with ScanTemplate's fields, the error is wrapped as 'unmarshal default scan template'. Like the other template errors, the data is compiled in, so this signals a broken source tree rather than a user-fixable runtime config.","triggerScenarios":"Calling LoadScanDefault() when defaultScanTemplate (from //go:embed scan_template.json) is not valid JSON or has fields whose types don't match ScanTemplate (e.g. MAX_TOKENS as a string, messages not an array).","commonSituations":"A bad merge left conflict markers in scan_template.json; a field was renamed in ScanTemplate but not in the JSON; hand-editing introduced a syntax error; the file was regenerated by a script with wrong types.","solutions":["Validate the JSON syntax of scan_template.json (jq . scan_template.json) and fix the error at the reported position","Cross-check keys against ScanTemplate's json tags and correct names/types","Make sure the file is plain UTF-8 without BOM","Rebuild so the corrected file is re-embedded into the binary"],"exampleFix":"// before (scan_template.json)\n{\"MAX_TOKENS\": \"4096\", \"MAIN_TASK\": {\"messages\": []}}\n// after\n{\"MAX_TOKENS\": 4096, \"MAIN_TASK\": {\"messages\": []}}","handlingStrategy":"validation","validationCode":"var probe map[string]any\nif err := json.Unmarshal(scanTemplateBytes, &probe); err != nil {\n\tlog.Fatalf(\"scan_template.json invalid: %v\", err)\n}\nif _, ok := probe[\"MAX_TOKENS\"].(float64); !ok { log.Fatal(\"scan_template.json MAX_TOKENS must be a number\") }","typeGuard":null,"tryCatchPattern":"stpl, err := template.LoadScanDefault()\nif err != nil {\n\tvar typeErr *json.UnmarshalTypeError\n\tif errors.As(err, &typeErr) {\n\t\treturn fmt.Errorf(\"scan_template.json field %s has incompatible type: %w\", typeErr.Field, err)\n\t}\n\treturn fmt.Errorf(\"scan template invalid: %w\", err)\n}","preventionTips":["Validate scan_template.json with a linter in CI before go build","Keep ScanTemplate json tags and the JSON keys in sync via a round-trip test","Avoid scripts that regenerate the JSON without validating output"],"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"}