In emacs's M-x shell:
$ RUST_BACKTRACE=1 cargo fmt
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', /Users/fitzgen/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_errors-0.43.0/src/emitter.rs:724
stack backtrace:
1: 0x10b5833ba - std::sys::backtrace::tracing::imp::write::h46f28e67d38b4637
2: 0x10b5856ef - std::panicking::default_hook::{{closure}}::h1d3243f546573ff4
3: 0x10b584bb5 - std::panicking::default_hook::h96c288d728df3ebf
4: 0x10b585166 - std::panicking::rust_panic_with_hook::hb1322e5f2588b4db
5: 0x10b585004 - std::panicking::begin_panic::hfbeda5aad583dc32
6: 0x10b584f22 - std::panicking::begin_panic_fmt::h4fe9fb9d5109c4bf
7: 0x10b4e9c99 - <syntex_errors::emitter::EmitterWriter as syntex_errors::emitter::Emitter>::emit::h59659432907ffdac
8: 0x10b4f3382 - syntex_errors::DiagnosticBuilder::emit::h69d5c96ffd49229d
9: 0x10b3d4b1d - rustfmt::format_input::h364b4d0ac3e55025
10: 0x10b3d8901 - rustfmt::run::h628aba487faebaab
11: 0x10b333150 - rustfmt::execute::h59d679989c4d799e
12: 0x10b334c96 - rustfmt::main::hfe15cf96550c7d30
13: 0x10b585caa - __rust_maybe_catch_panic
14: 0x10b5846f6 - std::rt::lang_start::haaae1186de9de8cb
Ideally, this would still format my rust code, skip whatever fancy colors or whatever are being attempted, and exit cleanly.
This happens to me wherever I try to run rustfmt on windows.
I tried the classic cmd prompt and power shell, happens in both.
Works in the cygwin shell though.
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.43.0\src\emitter.rs:724
stack backtrace:
0: 0x7ff73986701e - <unknown>
1: 0x7ff739865b73 - <unknown>
2: 0x7ff7398665dd - <unknown>
3: 0x7ff739866426 - <unknown>
4: 0x7ff739866384 - <unknown>
5: 0x7ff7397b55c8 - <unknown>
6: 0x7ff7397c329b - <unknown>
7: 0x7ff73970cf28 - <unknown>
8: 0x7ff73970e39d - <unknown>
9: 0x7ff739762ac0 - <unknown>
10: 0x7ff739762667 - <unknown>
11: 0x7ff739762508 - <unknown>
12: 0x7ff73973ade5 - <unknown>
13: 0x7ff7397425cb - <unknown>
14: 0x7ff73974d562 - <unknown>
15: 0x7ff73973880a - <unknown>
16: 0x7ff73974e4ac - <unknown>
17: 0x7ff739762228 - <unknown>
18: 0x7ff73965f045 - <unknown>
19: 0x7ff73965f89d - <unknown>
20: 0x7ff7396650fc - <unknown>
21: 0x7ff7395883cb - <unknown>
22: 0x7ff73958c5e7 - <unknown>
23: 0x7ff7398691e1 - <unknown>
24: 0x7ff73986541a - <unknown>
25: 0x7ff7398771af - <unknown>
26: 0x7ffc21f08363 - BaseThreadInitThunk
Happens to me as well. rustfmt 0.6.3 on Windows 7 using cmder and git bash as a shell. (edit: same thing happens in cmd.exe).
$ rustc -V
rustc 1.15.0-nightly (28d6623bc 2016-12-03)
$ cargo -V
cargo 0.16.0-nightly (3568be9 2016-11-26)
$ RUST_BACKTRACE=1 cargo fmt
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', C:\Users\USER\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.44.0\src\emitter.rs:724
stack backtrace:
0: 0x8580fe - <unknown>
1: 0x857906 - <unknown>
2: 0x8592ba - <unknown>
3: 0x859156 - <unknown>
4: 0x859079 - <unknown>
5: 0x76d042 - <unknown>
6: 0x777481 - <unknown>
7: 0x4c4ac0 - <unknown>
8: 0x40764e - <unknown>
9: 0x409319 - <unknown>
10: 0x858f38 - <unknown>
11: 0x863608 - <unknown>
12: 0x859a33 - <unknown>
13: 0x4013b4 - <unknown>
14: 0x4014e7 - <unknown>
15: 0x76e259bc - <unknown>
I think I fixed the issue, at least on a windows computer with powershell. When syntex tries to print a message it formats the message with term. But setting term::attr::Bold returns a NotSupported error.
@fitzgen @e00E @topecongiro @zsiciarz Anyone who still has this issue could you try replacing the rustfmt's syntex_errors and syntex_syntax dependency with my fork? It could be caused by something else on a different system and I want to test it.
@keringar Thank you for working on this issue! Unfortunately, it did not work in my environment (Arch Linux + eshell).
Backtrace:
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_errors/src/emitter.rs:1043
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::_print
at /checkout/src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at /checkout/src/libstd/sys_common/backtrace.rs:60
at /checkout/src/libstd/panicking.rs:355
3: std::panicking::default_hook
at /checkout/src/libstd/panicking.rs:371
4: std::panicking::rust_panic_with_hook
at /checkout/src/libstd/panicking.rs:549
5: std::panicking::begin_panic
at /checkout/src/libstd/panicking.rs:511
6: std::panicking::begin_panic_fmt
at /checkout/src/libstd/panicking.rs:495
7: syntex_errors::emitter::EmitterWriter::emit_messages_default
at /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_errors/src/emitter.rs:1043
8: <syntex_errors::emitter::EmitterWriter as syntex_errors::emitter::Emitter>::emit
at /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_errors/src/emitter.rs:37
9: syntex_errors::diagnostic_builder::DiagnosticBuilder::emit
at /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_errors/src/diagnostic_builder.rs:98
10: syntex_errors::Handler::fatal
at /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_errors/src/lib.rs:389
11: syntex_syntax::parse::file_to_filemap
at /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_syntax/src/parse/mod.rs:213
12: syntex_syntax::parse::new_parser_from_file
at /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/0fd2bf9/syntex_syntax/src/parse/mod.rs:160
13: rustfmt::parse_input
at ./src/lib.rs:546
14: rustfmt::format_input
at ./src/lib.rs:590
15: rustfmt::run
at ./src/lib.rs:651
16: rustfmt::execute
at ./src/bin/rustfmt.rs:275
17: rustfmt::main
at ./src/bin/rustfmt.rs:287
18: __rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:98
19: std::rt::lang_start
at /checkout/src/libstd/panicking.rs:433
at /checkout/src/libstd/panic.rs:361
at /checkout/src/libstd/rt.rs:57
20: main
21: __libc_start_main
22: _start
@topecongiro I updated my fork to check for all attributes before using them. Can you test it again?
I could not build rustfmt with your fork. Could you fix it?
error[E0308]: mismatched types
--> /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/78cf300/syntex_errors/src/emitter.rs:1284:36
|
1284 | if t.supports_attr(t) {
| ^ expected enum `term::Attr`, found mutable reference
|
= note: expected type `term::Attr`
found type `&mut std::boxed::Box<term::Terminal<Output=std::io::Stderr> + std::marker::Send + 'static>`
error[E0308]: mismatched types
--> /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/78cf300/syntex_errors/src/emitter.rs:1285:21
|
1285 | t.attr(attr)
| ^^^^^^^^^^^^ expected (), found enum `std::result::Result`
|
= note: expected type `()`
found type `std::result::Result<(), term::Error>`
error[E0308]: mismatched types
--> /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/78cf300/syntex_errors/src/emitter.rs:1289:36
|
1289 | if t.supports_attr(t) {
| ^ expected enum `term::Attr`, found mutable reference
|
= note: expected type `term::Attr`
found type `&mut std::boxed::Box<term::Terminal<Output=emitter::BufferedWriter> + std::marker::Send + 'static>`
error[E0308]: mismatched types
--> /home/topecongiro/.cargo/git/checkouts/syntex-2685e11a6b12fa00/78cf300/syntex_errors/src/emitter.rs:1290:21
|
1290 | t.attr(attr)
| ^^^^^^^^^^^^ expected (), found enum `std::result::Result`
|
= note: expected type `()`
found type `std::result::Result<(), term::Error>`
@topecongiro Sorry, please try again I pushed a fix. After the fix, I tested rustfmt on eshell, powershell and cmd and it doesn't panic. Might be fully fixed?
@keringar Thank your for updates! Unfortunately rustfmt still panics on eshell + Arch Linux. Backtrace is basically identical, so omitting it here.
@topecongiro Do you have a small example of the code I can test with?
The issues I encountered in eshell are:
rustfmt a)fn main() {
match x {
Some =>
}
}
@topecongiro I fixed it in arch with eshell. I'm running it in a vm, but it should be the same. Please test it again. Now instead of panicking with failed to emit error, it panics on something else. I don't know if that's a bug though. Files with syntax errors on the other hand, error as expected.
@keringar I tested with your latest changes and they work fine. Thank you for you great work!
Also, rustfmt panicking when a file does not exist can be prevented by explicitly checking the existence of the file in rustfmt rather than relegating it to syntex. I fell that nobody really cares, though I will create a PR shortly.
I submitted a PR to serde-rs/Syntex. It's a minor patch so as soon as it's accepted and pushed into crates.io rustfmt should automatically start using the updated version for new builds.
Most helpful comment
@topecongiro I fixed it in arch with eshell. I'm running it in a vm, but it should be the same. Please test it again. Now instead of panicking with
failed to emit error, it panics on something else. I don't know if that's a bug though. Files with syntax errors on the other hand, error as expected.