antonmedv/fx · error
Unexpected end of input in comment
Error message
Unexpected end of input in comment
What it means
While skipping a /* block comment in lenient mode, the parser scans for the closing */. If it hits EOF (p.char == 0) before finding it, the comment was never terminated, so it panics with 'Unexpected end of input in comment'. This protects against silently swallowing the rest of the document.
Source
Thrown at internal/jsonx/json.go:614
func (p *JsonParser) skipComment() {
p.next()
switch p.char {
case '/':
for p.char != '\n' && p.char != 0 {
p.next()
}
case '*':
for {
p.next()
if p.char == '*' {
p.next()
if p.char == '/' {
p.next()
return
}
}
if p.char == 0 {
panic("Unexpected end of input in comment")
}
}
default:
panic(fmt.Sprintf("Invalid comment: '/%c'", p.char))
}
}
View on GitHub (pinned to 4f31cd3a0c)
Solutions
- Close the block comment with */ in the input.
- Delete the unterminated /* comment entirely.
- If truncation is the cause, re-export/repair the source file.
- Use // line comments instead of /* */ for quick annotations.
Example fix
// before
{"a": 1 /* debug
// after
{"a": 1 /* debug */} Defensive patterns
Strategy: validation
Validate before calling
inBlock := false
for i := 0; i < len(data)-1; i++ {
if !inBlock && data[i] == '/' && data[i+1] == '*' { inBlock = true; i++ } else if inBlock && data[i] == '*' && data[i+1] == '/' { inBlock = false; i++ }
}
if inBlock {
return errors.New("unterminated /* comment in input")
} Try / catch
defer func() {
if r := recover(); r != nil {
if strings.Contains(fmt.Sprint(r), "end of input in comment") {
err = errors.New("close the /* */ comment in the input file")
}
}
}() Prevention
- Always close block comments immediately after opening them.
- Prefer // line comments for temporary annotations.
- Check file completeness when ingesting truncated or streamed data.
- Lint JSONC files before parsing.
When it happens
Trigger: Parsing non-strict JSON whose block comment lacks the closing */ — e.g. '{ "a": 1 /* oops' or a file truncated mid-comment.
Common situations: Manually commented-out sections of config where the closing */ was deleted, copy/paste dropping the last characters, log files truncated mid-write.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid comment: '/%c'
- Expected object key to be a string, got %q
- Expected colon after object key, got %q
- Unexpected character %q in object
- Invalid character %q in array
AI-assisted analysis of antonmedv/fx@4f31cd3a0c (2026-09-02).
Data as JSON: /api/errors/caf40772e7c2daa2.
Report an issue: GitHub.