fix: keep diagnostics off stdout - #48
Merged
Merged
Conversation
Reported from real use: a task that reads `sputnik completion bash` to compare it
against the installed file got a discovery warning as line one of the script.
$ sputnik completion bash | head -2
Skipped task 'list' in .../ProbeListTask.php: the name is reserved ...
# This file is part of the Symfony package.
The warning would have been written into the completion file. --silent and -q do
not help - they suppress the script along with the warning, because both were on
the same stream.
Diagnostics now go to stderr, where the redacting decorator already masks
secrets. Looking into it turned up the same class of bug in a place nobody had
tried: `list --format=json` was never parseable. Three separate things landed on
stdout around the JSON - the discovery warning, our header before it, and the
"Available tasks" section after it.
So for any list format other than the default txt, and for --raw, the decoration
is left out entirely: those exist to be read by something else.
completion bash stdout: # This file is part of the Symfony package.
stderr: Skipped task 'list' in ...
list --format=json valid JSON, 10 commands
list --raw the raw command list, nothing around it
list header and grouped task section, unchanged
The last line has its own test, because moving decoration behind a condition is
how you lose it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported from real use, and the reporter is right that it matters more than the migration that surfaced it. A task that reads
sputnik completion bashto compare it against the installed file got a discovery warning as line one of the script:That line would have been written into the completion file. And
--silent/-qare no help: they suppress the script along with the warning, because both were on the same stream. The consumer worked around it by stripping everything before the first#— a workaround in the wrong place.The same bug where nobody had looked
Diagnostics now go to stderr, which the redacting decorator already covers, so secrets stay masked there.
Checking whether
completionwas the only affected command turned up something worse:list --format=jsonhas never been parseable. Three separate things landed on stdout around the JSON — the discovery warning, our header before it, and theAvailable taskssection after it.So for any list format other than the default
txt, and for--raw, the decoration is left out entirely. Those formats exist to be read by something else.Verified against the binary
The last line has its own test, because moving decoration behind a condition is how you lose it.
Note on the reporter's other observation
The switching between "writes" and "is up to date" under 0.2.1 has the same root: the shadow warning was on stdout on every invocation, so it was captured into the file, which then never matched what the binary emitted next time. #46 made that a
-vnotice and this makes it stderr — both halves of that behaviour are gone now, and the consumer's#-stripping can go with them.Docs:
cli.mdstates that Sputnik's own diagnostics go to stderr and that--silentis the wrong tool for separating them, and documents--formatonlistwith ajqexample.🤖 Generated with Claude Code
https://claude.ai/code/session_018CTvnzcNYmFgm2HQcm821A