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

  1. Close the block comment with */ in the input.
  2. Delete the unterminated /* comment entirely.
  3. If truncation is the cause, re-export/repair the source file.
  4. 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

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

Related errors


AI-assisted analysis of antonmedv/fx@4f31cd3a0c (2026-09-02). Data as JSON: /api/errors/caf40772e7c2daa2. Report an issue: GitHub.