{"record":{"id":"98a7e91278880d96","repo":"antonmedv/fx","slug":"invalid-comment-c","errorCode":null,"errorMessage":"Invalid comment: '/%c'","messagePattern":"Invalid comment: '/%c'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/json.go","lineNumber":618,"sourceCode":"\t\tfor p.char != '\\n' && p.char != 0 {\n\t\t\tp.next()\n\t\t}\n\tcase '*':\n\t\tfor {\n\t\t\tp.next()\n\t\t\tif p.char == '*' {\n\t\t\t\tp.next()\n\t\t\t\tif p.char == '/' {\n\t\t\t\t\tp.next()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\tif p.char == 0 {\n\t\t\t\tpanic(\"Unexpected end of input in comment\")\n\t\t\t}\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Invalid comment: '/%c'\", p.char))\n\t}\n}\n","sourceCodeStart":600,"sourceCodeEnd":621,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/json.go#L600-L621","documentation":"skipComment is invoked after seeing '/'. A valid comment must start with '//' (line) or '/*' (block). Any other character following the slash — e.g. a single '/' followed by something else like '/=' or '/ x' — falls into the default branch and panics with the exact offending pair. The %c verb may render an empty/EOF char oddly, but the cause is always an unrecognized comment start.","triggerScenarios":"Parsing lenient-mode JSON containing a stray '/' that is not part of // or /*, e.g. '{ \"a\": 1 } / 2', 'x /= 2' inside a JSON-ish document, or a regex literal pasted into JSON.","commonSituations":"Pasting JavaScript snippets into .json files, division or regex syntax in config, typos where a comment opener was half-typed ('/ note').","solutions":["Fix the comment opener to be either // or /*.","Remove the stray '/' character from the input.","Complete a half-written comment (e.g. '/ text' → '// text').","Validate the file as real JSON/JSONC before feeding it to the parser."],"exampleFix":"// before\n{\"a\": 1} / note\n// after\n{\"a\": 1} // note","handlingStrategy":"validation","validationCode":"re := regexp.MustCompile(`/(?!/|\\*)`)\nif re.Match(data) {\n    return fmt.Errorf(\"stray '/' at byte offset %d: comments must start with // or /*\", re.FindIndex(data)[0])\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.HasPrefix(fmt.Sprint(r), \"Invalid comment\") {\n            err = fmt.Errorf(\"fix the comment opener: %v\", r)\n        }\n    }\n}()","preventionTips":["Never paste JavaScript code (division, regex) into JSON documents.","Complete half-typed comment openers ('/ ' → '// ').","Lint the file before parsing to catch stray slashes.","Restrict lenient-mode parsing to trusted, reviewed inputs."],"tags":["json","comment","syntax","parser"],"backgroundTag":"invalid-json-syntax","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}