ivandardi / RustbotPython

A Discord bot for the Community Rust Language server, written in Python.
MIT License
16 stars 9 forks source link

If rustc error output is too large, print a subset of errors #21

Open kangalio opened 3 years ago

kangalio commented 3 years ago

Currently, if the error text produces by rustc is too large to be displayed in a Discord message (2000 characters), this bot prints a playground link instead that you have to go to and click play on in order to see what went wrong.

This is annoying, because you have to change context (Discord -> Playground). And after you're done fixing the errors in the playground, you need to transfer over your code back to Discord. It would be great if this could be made more streamlined:

By just omitting the end of the rustc errors if there are too many. Something like

error[E0277]: cannot add-assign `()` to `{integer}`
 --> src/main.rs:9:9
  |
9 |     sum += arg;
  |         ^^ no implementation for `{integer} += ()`
  |
  = help: the trait `AddAssign<()>` is not implemented for `{integer}`

error[E0308]: mismatched types
  --> src/main.rs:10:15
   |
10 |     if arg == 0 { break }
   |               ^ expected `()`, found integer

error[E0599]: no method named `resume` found for generator `[generator@src/main.rs:5:21: 13:2]` in the current scope
  --> src/main.rs:15:16
   |
15 | dbg!(generator.resume(4));
   |                ^^^^^^ method not found in `[generator@src/main.rs:5:21: 13:2]`

36 lines were cut off. See the full output: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7a41ea15be90ad65aafa635f3ef74161

This would allow you to stay in Discord to edit your code. You'd just fix the errors that are displayed in the 2000 character subset, until everything compiles fine!

This would be great

EDIT: there's also no reason not to expand this to also work with regular output. In other words, normal program output will also be properly truncated to fit if too large, instead of not being shown at all.