antonmedv/fx · error

Invalid comment: '/%c'

Error message

Invalid comment: '/%c'

What it means

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.

Source

Thrown at internal/jsonx/json.go:618

		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. Fix the comment opener to be either // or /*.
  2. Remove the stray '/' character from the input.
  3. Complete a half-written comment (e.g. '/ text' → '// text').
  4. Validate the file as real JSON/JSONC before feeding it to the parser.

Example fix

// before
{"a": 1} / note
// after
{"a": 1} // note
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`/(?!/|\*)`)
if re.Match(data) {
    return fmt.Errorf("stray '/' at byte offset %d: comments must start with // or /*", re.FindIndex(data)[0])
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        if strings.HasPrefix(fmt.Sprint(r), "Invalid comment") {
            err = fmt.Errorf("fix the comment opener: %v", r)
        }
    }
}()

Prevention

When it happens

Trigger: 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.

Common situations: Pasting JavaScript snippets into .json files, division or regex syntax in config, typos where a comment opener was half-typed ('/ note').

Related errors


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