ruff/crates/ruff_cli/src
Charlie Marsh 60132da7bb
Add a `NotebookError` type to avoid returning `Diagnostics` on error (#7035)
## Summary

This PR refactors the error-handling cases around Jupyter notebooks to
use errors rather than `Box<Diagnostics>`, which creates some oddities
in the downstream handling. So, instead of formatting errors as
diagnostics _eagerly_ (in the notebook methods), we now return errors
and convert those errors to diagnostics at the last possible moment (in
`diagnostics.rs`). This is more ergonomic, as errors can be composed and
reported-on in different ways, whereas diagnostics require a `Printer`,
etc.

See, e.g.,
https://github.com/astral-sh/ruff/pull/7013#discussion_r1311136301.

## Test Plan

Ran `cargo run` over a Python file labeled with a `.ipynb` suffix, and
saw:

```
foo.ipynb:1:1: E999 SyntaxError: Expected a Jupyter Notebook, which must be internally stored as JSON, but found a Python source file: expected value at line 1 column 1
```
2023-09-01 11:08:05 +00:00
..
bin Replace `.map_or(false, $closure)` with `.is_some_and(closure)` (#6244) 2023-08-01 19:29:42 +02:00
commands Reuse `FormatResult` and `FormatterIterationError` in `format_stdin.rs` (#6985) 2023-08-29 17:41:53 +00:00
args.rs Add hidden `--preview` / `--no-preview` options to `ruff check` (#7009) 2023-08-31 09:51:59 -05:00
cache.rs Refactor `SourceKind` to store file content (#6640) 2023-08-18 13:45:38 +00:00
diagnostics.rs Add a `NotebookError` type to avoid returning `Diagnostics` on error (#7035) 2023-09-01 11:08:05 +00:00
lib.rs Move stdin formatting to its own command file (#6981) 2023-08-29 16:06:10 +00:00
panic.rs Disallow `unreachable_pub` (#4314) 2023-05-11 18:00:00 -04:00
printer.rs Refactor `SourceKind` to store file content (#6640) 2023-08-18 13:45:38 +00:00
resolve.rs Move `Configuration` to `ruff_workspace` crate (#6920) 2023-08-28 06:21:35 +00:00
stdin.rs Move stdin formatting to its own command file (#6981) 2023-08-29 16:06:10 +00:00