Skip to content

fix: redirect debug/status output to stderr for json/xml output formats#573

Merged
buger merged 1 commit into
probelabs:mainfrom
sridhar-3009:fix/symbols-debug-output-to-stderr
Jun 3, 2026
Merged

fix: redirect debug/status output to stderr for json/xml output formats#573
buger merged 1 commit into
probelabs:mainfrom
sridhar-3009:fix/symbols-debug-output-to-stderr

Conversation

@sridhar-3009

Copy link
Copy Markdown
Contributor

Problem

Closes #568.

When probe is called with --format=json (e.g. via the MCP symbols tool), debug lines like Pattern: ..., Path: ..., and Falling back to BM25 ranking... were written to stdout before the JSON result. Any JSON parser downstream received:

Pattern: symbols
Path: '/tmp/...'
Options: Reranker: bm25
Using BM25 ranking (Okapi BM25 algorithm)
{"results": [], ...}

And failed with: Unexpected token 'P', "Pattern: s"... is not valid JSON

Fix

src/main.rs — wrap the Pattern: and Path: println! blocks in a format guard so they are only printed for text output:

if params.format != "json" && params.format != "xml" {
    println!("{} {}", "Pattern:".bold().green(), params.pattern);
}

src/search/result_ranking.rs — change "Falling back to BM25 ranking..." and related debug println! calls to eprintln!.

src/ranking.rs — same for SIMD debug messages.

All status/diagnostic output now goes to stderr, leaving stdout clean JSON for downstream parsers.

When MCP tools call probe with --format=json (or xml), debug lines like
"Pattern: ...", "Path: ...", and "Falling back to BM25 ranking..." were
written to stdout. The JSON parser received these lines before the actual
JSON payload and failed with "Unexpected token 'P'...".

Changes:
- main.rs: guard the Pattern/Path println! blocks behind a format check
  so they are only printed for text output (not json/xml)
- result_ranking.rs: change "Falling back to BM25 ranking..." and related
  debug println! calls to eprintln! so they go to stderr regardless of
  output format
- ranking.rs: same — SIMD debug messages to eprintln!

Fixes #568
@buger

buger commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Yep, makes sense! Thank you!

@buger
buger merged commit 1f629e8 into probelabs:main Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

symbols tool: JSON parse failure due to debug output on stdout

2 participants