|
1 | 1 | use crate::shell_quoted::ShellQuoted;
|
2 |
| -use derive_more::{Display, From}; |
3 | 2 | use std::{env::JoinPathsError, io, num::NonZeroI32, path::PathBuf};
|
4 | 3 |
|
5 | 4 | /// Error types emitted by `pn` itself.
|
6 |
| -#[derive(Debug, Display)] |
| 5 | +#[derive(Debug, thiserror::Error)] |
7 | 6 | pub enum PnError {
|
8 | 7 | /// Script not found when running `pn run`.
|
9 |
| - #[display("Missing script: {name}")] |
| 8 | + #[error("Missing script: {name}")] |
10 | 9 | MissingScript { name: String },
|
11 | 10 |
|
12 | 11 | /// Script ran by `pn run` exits with non-zero status code.
|
13 |
| - #[display("Command failed with exit code {status}")] |
| 12 | + #[error("Command failed with exit code {status}")] |
14 | 13 | ScriptError { name: String, status: NonZeroI32 },
|
15 | 14 |
|
16 | 15 | /// Subprocess finishes but without a status code.
|
17 |
| - #[display("Command ended unexpectedly: {command}")] |
| 16 | + #[error("Command ended unexpectedly: {command}")] |
18 | 17 | UnexpectedTermination { command: ShellQuoted },
|
19 | 18 |
|
20 | 19 | /// Fail to spawn a subprocess.
|
21 |
| - #[display("Failed to spawn process: {_0}")] |
22 |
| - SpawnProcessError(io::Error), |
| 20 | + #[error("Failed to spawn process: {0}")] |
| 21 | + SpawnProcessError(#[source] io::Error), |
23 | 22 |
|
24 | 23 | /// Fail to wait for the subprocess to finish.
|
25 |
| - #[display("Failed to wait for the process: {_0}")] |
26 |
| - WaitProcessError(io::Error), |
| 24 | + #[error("Failed to wait for the process: {0}")] |
| 25 | + WaitProcessError(#[source] io::Error), |
27 | 26 |
|
28 | 27 | /// The program receives --workspace-root outside a workspace.
|
29 |
| - #[display("--workspace-root may only be used in a workspace")] |
| 28 | + #[error("--workspace-root may only be used in a workspace")] |
30 | 29 | NotInWorkspace,
|
31 | 30 |
|
32 | 31 | /// No package manifest.
|
33 |
| - #[display("File not found: {file:?}")] |
| 32 | + #[error("File not found: {file:?}")] |
34 | 33 | NoPkgManifest { file: PathBuf },
|
35 | 34 |
|
36 | 35 | /// Error related to filesystem operation.
|
37 |
| - #[display("{path:?}: {error}")] |
38 |
| - FsError { path: PathBuf, error: io::Error }, |
| 36 | + #[error("{path:?}: {error}")] |
| 37 | + FsError { path: PathBuf, #[source] error: io::Error }, |
39 | 38 |
|
40 | 39 | /// Error emitted by [`lets_find_up`]'s functions.
|
41 |
| - #[display("Failed to find {file_name:?} from {start_dir:?} upward: {error}")] |
| 40 | + #[error("Failed to find {file_name:?} from {start_dir:?} upward: {error}")] |
42 | 41 | FindUpError {
|
43 | 42 | start_dir: PathBuf,
|
44 | 43 | file_name: &'static str,
|
| 44 | + #[source] |
45 | 45 | error: io::Error,
|
46 | 46 | },
|
47 | 47 |
|
48 | 48 | /// An error is encountered when write to stdout.
|
49 |
| - #[display("Failed to write to stdout: {_0}")] |
| 49 | + #[error("Failed to write to stdout: {0}")] |
50 | 50 | WriteStdoutError(io::Error),
|
51 | 51 |
|
52 | 52 | /// Parse JSON error.
|
53 |
| - #[display("Failed to parse {file:?}: {message}")] |
| 53 | + #[error("Failed to parse {file:?}: {message}")] |
54 | 54 | ParseJsonError { file: PathBuf, message: String },
|
55 | 55 |
|
56 | 56 | /// Failed to prepend `node_modules/.bin` to `PATH`.
|
57 |
| - #[display("Cannot add `node_modules/.bin` to PATH: {_0}")] |
| 57 | + #[error("Cannot add `node_modules/.bin` to PATH: {0}")] |
58 | 58 | NodeBinPathError(JoinPathsError),
|
59 | 59 | }
|
60 | 60 |
|
61 | 61 | /// The main error type.
|
62 |
| -#[derive(Debug, Display, From)] |
| 62 | +#[derive(Debug, thiserror::Error)] |
63 | 63 | pub enum MainError {
|
64 | 64 | /// Errors emitted by `pn` itself.
|
65 |
| - Pn(PnError), |
| 65 | + #[error(transparent)] |
| 66 | + Pn(#[from] PnError), |
66 | 67 |
|
67 | 68 | /// The subprocess that takes control exits with non-zero status code.
|
68 |
| - #[from(ignore)] |
| 69 | + #[error("{0}")] |
69 | 70 | Sub(NonZeroI32),
|
70 | 71 | }
|
0 commit comments