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

fix: Write diagnostics to stderr (vs stdout) #1978

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

imikushin
Copy link

@imikushin imikushin commented Jan 24, 2025

Motivation

Before this change (even when logging was not enabled) SP1 was writing diagnostic messages to stdout, breaking the implicit contract that only the application logic should decide what gets written to stdout. This contract is important, e.g. for passing the output for further processing in shell-driven use cases:

cat ./input-data.json | my-app | another-app

This change aims to fix this issue, and to safeguard against it (to a reasonable extent) in the future.

Solution

  • Change println! usages to eprintln! in production modules.
  • Add clippy warnings to runtime modules guarding against using printing to stdout. eprintln! is okay 👍.
  • Add exceptions to the above clippy warnings to tests and build scripts.
  • Direct logging output to stderr by default.

I've left alone tests, examples and build scripts, and tried to make the change as narrow as possible so it affects only production code paths.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Before this change (even when logging was not enabled) SP1 was writing diagnostic messages to stdout, breaking the implicit contract that only the application logic should decide what gets written to stdout.
This contract is important, e.g. for passing the output for further processing in shell-driven use cases:

```sh
cat ./input-data.json | my-app | another-app
```

This change aims to fix this issue, and to safeguard against it (to a reasonable extent) in the future.

I've left alone tests, examples and build scripts, and tried to make the change as narrow as possible and to affect only the production code paths.
Copy link
Member

@ratankaliani ratankaliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @imikushin!

Can you move the warn! and allow! attributes to the TOML files, rather than in .rs?

This will avoid replication like what we see in crates/core/machine/src/**.

By the way, have you confirmed this branch works as you expect?

@imikushin
Copy link
Author

@ratankaliani I believe the CI only complained about formatting: fixed that.

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.

3 participants