{"record":{"id":"777f77636eeec7af","repo":"plandex-ai/plandex","slug":"unmarshal-error-w","errorCode":null,"errorMessage":"unmarshal error: %w","messagePattern":"unmarshal error: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/schema/schemas.go","lineNumber":78,"sourceCode":"\n\tschemaLoader := newEmbeddedSchemaLoader(schemaPath)\n\tdocumentLoader := gojsonschema.NewBytesLoader(jsonData)\n\n\tresult, err := gojsonschema.Validate(schemaLoader, documentLoader)\n\tif err != nil {\n\t\treturn zero, err\n\t}\n\tif !result.Valid() {\n\t\tvar msgs []string\n\t\tfor _, d := range result.Errors() {\n\t\t\tmsgs = append(msgs, \"• \"+d.String())\n\t\t}\n\t\treturn zero, errors.New(strings.Join(msgs, \"\\n\"))\n\t}\n\n\tvar v T\n\tif err := json.Unmarshal(jsonData, &v); err != nil {\n\t\treturn zero, fmt.Errorf(\"unmarshal error: %w\", err)\n\t}\n\treturn v, nil\n}\n\nfunc newEmbeddedSchemaLoader(source SchemaPath) *embeddedSchemaLoader {\n\treturn &embeddedSchemaLoader{\n\t\tsource: string(source),\n\t\tfs:     schemaFS,\n\t}\n}\n\nfunc (l *embeddedSchemaLoader) JsonSource() interface{} {\n\treturn l.source\n}\n\nfunc (l *embeddedSchemaLoader) LoadJSON() (interface{}, error) {\n\t// remove both \"./\" and the scheme prefix\n\tsource := strings.TrimPrefix(l.source, \"./\")","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/schema/schemas.go#L60-L96","documentation":"After the document passes gojsonschema validation, validateJSON unmarshals the cleaned JSON into the concrete generic type T. This error means the JSON is structurally valid but does not decode into T — typically wrong field types (string where number expected, object where array expected).","triggerScenarios":"ValidateModelsInputJSON / ValidateModelPackInlineJSON given JSON that is valid but whose fields don't match T's Go types: e.g. \"maxTokens\": \"4096\" (string) instead of a number, or a flat object where a nested object is required.","commonSituations":"Hand-edited model config with quoted numbers; schema validation passing because additionalProperties was relaxed but the typed struct is stricter; API version drift changing field shapes.","solutions":["Check the wrapped json.Unmarshal message naming the mismatched field/type","Compare your JSON against the JSON schema for the expected types","Fix field types (remove quotes around numbers, correct nesting)","Regenerate the config from a known-good template"],"exampleFix":"// before\n{\"maxTokens\": \"4096\"}\n// after\n{\"maxTokens\": 4096}","handlingStrategy":"validation","validationCode":"// decode into T yourself first with strict errors to get a precise message\nvar probe T\nif err := json.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"input does not match expected shape: %w\", err)\n}","typeGuard":"func decodesAs[T any](b []byte) bool {\n    var v T\n    return json.Unmarshal(b, &v) == nil\n}","tryCatchPattern":"err := ValidateModelsInputJSON(data)\nif err != nil && strings.HasPrefix(err.Error(), \"unmarshal error:\") {\n    var ute *json.UnmarshalTypeError\n    if errors.As(err, &ute) {\n        log.Printf(\"field %s: expected %s\", ute.Field, ute.Type)\n    }\n}","preventionTips":["Match the schema's declared types exactly (numbers unquoted, correct nesting)","Generate configs from templates instead of hand-editing","Pin schema/struct versions so field shapes don't drift","Run validation on save in your editor with the matching JSON schema"],"tags":["json","type-mismatch","unmarshal"],"backgroundTag":"json-type-mismatch","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}