antonmedv/fx · error

%s on line %d. %s

Error message

%s on line %d.

%s

What it means

Formats the human-readable parse error shown for invalid JSON input: it builds a caret-pointing snippet of the offending line (width clamped to terminal size, defaulting to 80 columns) and embeds the parser message with its line number. This is a formatting helper, not an independent failure — the message reflects whatever JSON syntax error the parser hit.

Source

Thrown at internal/jsonx/format_err.go:30

func (p *JsonParser) errorSnippet(message string) error {
	termWidth, _, err := term.GetSize(os.Stdout.Fd())
	if err != nil {
		termWidth = 80
	}
	maxWidth := min(termWidth, 60)
	maxWidth -= 2
	maxWidth = max(maxWidth, 10)

	// As we already moved end pointer in next(), we need to move it back.
	p.end -= 1

	before, width := p.contextBefore(maxWidth / 2)
	after, _ := p.contextAfter(maxWidth - width)
	snippet := "  " + before + after
	snippet += "\n  " + strings.Repeat(".", max(0, width-1)) + "^"

	return fmt.Errorf(
		"%s on line %d.\n\n%s\n",
		message,
		p.realLineNumber,
		snippet,
	)
}

func (p *JsonParser) contextBefore(maxWidth int) (s string, width int) {
	pos := p.end + 1
	if pos > len(p.data) {
		pos = len(p.data)
	}
	data := p.data[:pos]
	for len(data) > 0 {
		r, size := utf8.DecodeLastRune(data)
		if r == '\n' {
			break
		}

View on GitHub (pinned to 4f31cd3a0c)

Solutions

  1. Fix the JSON syntax at the indicated line and column in the input
  2. Validate the JSON with a linter before feeding it to fx
  3. Check for truncated files or stray characters around the marked caret
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/jsonx/format_err.go:30 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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