Skip to content

fix: keep stdout pure JSON by redirecting result.Message to stderr for non-default formats - #71

Merged
mbellotti merged 2 commits into
mainfrom
copilot/fix-json-format-template
Jul 23, 2026
Merged

fix: keep stdout pure JSON by redirecting result.Message to stderr for non-default formats#71
mbellotti merged 2 commits into
mainfrom
copilot/fix-json-format-template

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

When --format json is used and the solver returns unsat, the human-readable result.Message was unconditionally printed to stdout before the JSON output, producing mixed content that breaks any JSON consumer.

Change

main.go — mirrors the existing warnings suppression pattern for result.Message:

// Before: message always went to stdout, contaminating JSON output
if formatTmpl == "default" {
    for _, w := range result.Warnings {
        fmt.Fprintln(os.Stderr, w)
    }
}
if result.Message != "" {
    fmt.Println(result.Message)
}

// After: message follows warnings — stdout only for default, stderr for structured formats
if formatTmpl == "default" {
    for _, w := range result.Warnings {
        fmt.Fprintln(os.Stderr, w)
    }
    if result.Message != "" {
        fmt.Println(result.Message)
    }
} else if result.Message != "" {
    fmt.Fprintln(os.Stderr, result.Message)
}

For the default (human-readable) format, behaviour is unchanged. For json and any custom template format, stdout is now pure structured output.

Copilot AI linked an issue Jul 22, 2026 that may be closed by this pull request
When --format json (or any non-default format) is used, result.Message
was unconditionally printed to stdout before the JSON output, making
the combined stdout invalid JSON.

Mirror the existing warnings pattern: for non-default formats send the
message to stderr so stdout remains pure JSON; for the default format
the behaviour is unchanged.

Fixes #70
Copilot AI changed the title [WIP] Fix json format template contamination issue fix: keep stdout pure JSON by redirecting result.Message to stderr for non-default formats Jul 22, 2026
Copilot AI requested a review from mbellotti July 22, 2026 14:26
@mbellotti
mbellotti marked this pull request as ready for review July 23, 2026 02:27
@mbellotti
mbellotti merged commit 9275a5a into main Jul 23, 2026
1 check passed
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.

Json format template includes other text

2 participants