{"record":{"id":"1873cc4af2a99719","repo":"chenhg5/cc-connect","slug":"parse-json-from-s-w-1873cc","errorCode":null,"errorMessage":"parse JSON from %s: %w","messagePattern":"parse JSON from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/skill_presets.go","lineNumber":138,"sourceCode":"\tclient := &http.Client{Timeout: timeout}\n\tresp, err := client.Get(url)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"HTTP GET %s: %w\", url, err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"HTTP GET %s: status %d\", url, resp.StatusCode)\n\t}\n\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read body from %s: %w\", url, err)\n\t}\n\n\tvar result SkillPresetsResponse\n\tif err := json.Unmarshal(body, &result); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse JSON from %s: %w\", url, err)\n\t}\n\treturn &result, nil\n}\n","sourceCodeStart":120,"sourceCodeEnd":142,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/skill_presets.go#L120-L142","documentation":"fetchSkillPresetsFromURL wraps json.Unmarshal failures of the downloaded body with \"parse JSON from %s: %w\". The HTTP layer fully succeeded, but the payload is not valid JSON or does not fit SkillPresetsResponse. This indicates a broken or wrong content source rather than a network problem.","triggerScenarios":"A source URL serving HTML (error/redirect page), an empty body, truncated JSON from an interrupted transfer, or a JSON schema that no longer matches SkillPresetsResponse during fetch.","commonSituations":"URL pointing at a human-readable docs page instead of the raw JSON file; GitHub URL not switched to raw.githubusercontent.com; upstream renamed fields after a schema version bump.","solutions":["Save the body (curl the URL) and validate it: jq . body.json — fix the URL to point at the actual JSON file","Verify the response schema still matches SkillPresetsResponse; update the struct or pin a compatible presets version","Ensure the URL serves raw JSON (e.g. raw.githubusercontent.com) not an HTML page","Check Content-Type; some hosts return HTML interstitials to unknown User-Agents"],"exampleFix":"// before\nurl = \"https://github.com/org/skills-presets\"            // HTML page\n// after\nurl = \"https://raw.githubusercontent.com/org/skills-presets/main/presets.json\"","handlingStrategy":"validation","validationCode":"resp, err := http.Get(sourceURL)\nif err == nil {\n    ct := resp.Header.Get(\"Content-Type\")\n    b, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n    if !strings.Contains(ct, \"json\") || !json.Valid(b) {\n        return fmt.Errorf(\"%s does not serve valid JSON (content-type %s)\", sourceURL, ct)\n    }\n    var probe SkillPresetsResponse\n    if err := json.Unmarshal(b, &probe); err != nil {\n        return fmt.Errorf(\"schema mismatch for %s: %w\", sourceURL, err)\n    }\n}","typeGuard":"func servesJSON(url string) bool {\n    resp, err := http.Get(url)\n    if err != nil { return false }\n    defer resp.Body.Close()\n    b, err := io.ReadAll(io.LimitReader(resp.Body, 4096))\n    return err == nil && json.Valid(b)\n}","tryCatchPattern":"presets, err := fetchSkillPresetsFromURL(url, timeout)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"parse JSON from\") {\n        slog.Error(\"presets source returned invalid JSON; check URL points at raw JSON file\", \"url\", url, \"err\", err)\n    }\n    return err\n}","preventionTips":["Point preset URLs at raw JSON files (raw.githubusercontent.com), never HTML pages","Validate downloaded presets with jq or json.Valid after any upstream schema change","Pin a compatible presets version and update deliberately when SkillPresetsResponse changes"],"tags":["json","http","parsing"],"backgroundTag":"invalid-json-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}