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

Writing non-utf8 data to stdout suppresses compiler messages #386

Open
trentj opened this issue Aug 22, 2018 · 3 comments
Open

Writing non-utf8 data to stdout suppresses compiler messages #386

trentj opened this issue Aug 22, 2018 · 3 comments
Labels
bug The playground isn't doing what it was intended to help wanted Not immediately going to be prioritized — ask for mentoring instructions!

Comments

@trentj
Copy link

trentj commented Aug 22, 2018

Here's a simple example:

use std::io::{stdout, Write};
fn main() {
    stdout().write(b"\x91");
}

The only output, in the "Errors" section, is the message Sandbox operation failed: Output was not valid UTF-8: invalid utf-8 sequence of 1 bytes from index 0, which, although true, does not contain any compiler warnings or confirmation that compilation was successful. (At first, I thought this might be a connectivity issue or something of that nature.)

I want to see compiler output regardless of whether there is a problem with the actual program stdout. In this case, if you replace \x91 with some valid UTF-8 string, you see the following in the "Standard Error" section, which was absent in the original example:

   Compiling playground v0.0.1 (file:///playground)
warning: unused `std::result::Result` which must be used
 --> src/main.rs:3:5
  |
3 |     stdout().write(b"\x61");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_must_use)] on by default
  = note: this `Result` may be an `Err` variant, which should be handled

    Finished dev [unoptimized + debuginfo] target(s) in 1.31s
     Running `target/debug/playground`
@RalfJung
Copy link
Member

This just lead to lots of confusion in rust-lang/rust#58776 because I did not realize that it was playground showing the error, instead of rustc or the application.

@shepmaster what about using from_utf8_lossy to handle non-UTF-8 output more gracefully?

@shepmaster shepmaster added bug The playground isn't doing what it was intended to help wanted Not immediately going to be prioritized — ask for mentoring instructions! labels Feb 27, 2019
@shepmaster
Copy link
Member

I think something along the lines of from_utf8 and on failure try from_utf8_lossy and add some text to the returned warnings would be reasonable.

@RalfJung
Copy link
Member

RalfJung commented Apr 7, 2020

Curiously, running the same example program in Miri does not suppress any output. Instead it prints the compiler warnings, and then the program output as

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The playground isn't doing what it was intended to help wanted Not immediately going to be prioritized — ask for mentoring instructions!
Projects
None yet
Development

No branches or pull requests

3 participants