Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(output): force standard format when tracing is enabled #1060

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thevilledev
Copy link
Contributor

When --trace flag is used, override any output format to use standard format. This ensures consistent trace output and better debugging experience.

Changes:

  • Add tracing check in output.Get()
  • Update test command help text to clarify behavior
  • Refactor output tests to be more maintainable
    • Add default test options
    • Use pointer for optional test settings
    • Improve test error messages

Fixes #1031

When `--trace` flag is used, override any output format to use standard
format. This ensures consistent trace output and better debugging
experience.

Changes:
- Add tracing check in output.Get()
- Update test command help text to clarify behavior
- Refactor output tests to be more maintainable
  - Add default test options
  - Use pointer for optional test settings
  - Improve test error messages

Signed-off-by: Ville Vesilehto <[email protected]>
@thevilledev thevilledev force-pushed the fix/trace-with-output branch from 22b9b7e to 0dea545 Compare February 10, 2025 15:59
@jalseth
Copy link
Member

jalseth commented Feb 11, 2025

I am concerned that this will break users who accidentally have --trace enabled with an output other than Standard. I think the --output flag is more important to prioritize.

Is it possible to enable tracing without changing the output style?

@thevilledev
Copy link
Contributor Author

thevilledev commented Feb 11, 2025

At this time tracing is only implemented in the standard output format. Since choosing the output format is a single pass it's one or the other. If we prioritise output over trace then the only option would be to ignore it, which is what conftest is already doing. Maybe give a warning, although if the warning is written to stdout it will break piping use cases like conftest test <args> | jq .

A bit of a larger refactoring would be to separate trace output handling from the output format and write it to a separate stream. Quite common approach for debug/trace outputs. Something like this:

  • Default behavior (no -o flag):
    • Standard output format → stdout
    • Trace info (if enabled) → stderr
  • Custom output (with -o flag):
    • Chosen format (table/json/etc) → stdout
    • Trace info in standard format (if enabled) → stderr

So with conftest test --trace -o json you would see both trace and the json output but on different streams, enabling piping as before and likely less of a breaking change for many.

@jalseth
Copy link
Member

jalseth commented Feb 19, 2025

That makes sense, thanks. For now, I'd like to leave it as-is with preference for the output flag, and we can add to the description of the trace flag to clarify that it only has an effect for the standard output.

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.

Trace is not outputted when --output=table
2 participants