diff options
author | Wilco Kusee <[email protected]> | 2020-01-03 13:10:50 +0000 |
---|---|---|
committer | Wilco Kusee <[email protected]> | 2020-01-03 13:34:16 +0000 |
commit | 6c321d7318b94ee93dc60dc88d1e68afa94e8c4f (patch) | |
tree | 959822979e426fc98b20e86f6183ace49a16656f /crates | |
parent | 2202891221647c9c1a1c6bd47c0b0214b364803d (diff) |
Move error to new file
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 58 | ||||
-rw-r--r-- | crates/ra_project_model/src/workspace_error.rs | 57 |
2 files changed, 61 insertions, 54 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 49710b358..c07c54936 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -3,9 +3,9 @@ | |||
3 | mod cargo_workspace; | 3 | mod cargo_workspace; |
4 | mod json_project; | 4 | mod json_project; |
5 | mod sysroot; | 5 | mod sysroot; |
6 | mod workspace_error; | ||
6 | 7 | ||
7 | use std::{ | 8 | use std::{ |
8 | fmt, | ||
9 | fs::File, | 9 | fs::File, |
10 | io::BufReader, | 10 | io::BufReader, |
11 | path::{Path, PathBuf}, | 11 | path::{Path, PathBuf}, |
@@ -13,68 +13,18 @@ use std::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use ra_cfg::CfgOptions; | 15 | use ra_cfg::CfgOptions; |
16 | use ra_db::{CrateGraph, CrateId, Edition, Env, FileId, ParseEditionError}; | 16 | use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; |
17 | use rustc_hash::FxHashMap; | 17 | use rustc_hash::FxHashMap; |
18 | use serde_json::from_reader; | 18 | use serde_json::from_reader; |
19 | 19 | ||
20 | use crate::workspace_error::WorkspaceError; | ||
21 | |||
20 | pub use crate::{ | 22 | pub use crate::{ |
21 | cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind}, | 23 | cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind}, |
22 | json_project::JsonProject, | 24 | json_project::JsonProject, |
23 | sysroot::Sysroot, | 25 | sysroot::Sysroot, |
24 | }; | 26 | }; |
25 | 27 | ||
26 | #[derive(Debug)] | ||
27 | pub enum WorkspaceError { | ||
28 | CargoMetadataFailed(cargo_metadata::Error), | ||
29 | CargoTomlNotFound(PathBuf), | ||
30 | NoStdLib(PathBuf), | ||
31 | OpenWorkspaceError(std::io::Error), | ||
32 | ParseEditionError(ParseEditionError), | ||
33 | ReadWorkspaceError(serde_json::Error), | ||
34 | RustcCfgError, | ||
35 | RustcError(std::io::Error), | ||
36 | RustcOutputError(std::string::FromUtf8Error), | ||
37 | SysrootNotFound, | ||
38 | } | ||
39 | |||
40 | impl fmt::Display for WorkspaceError { | ||
41 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
42 | match self { | ||
43 | Self::OpenWorkspaceError(err) | Self::RustcError(err) => write!(f, "{}", err), | ||
44 | Self::ParseEditionError(err) => write!(f, "{}", err), | ||
45 | Self::ReadWorkspaceError(err) => write!(f, "{}", err), | ||
46 | Self::RustcOutputError(err) => write!(f, "{}", err), | ||
47 | Self::CargoMetadataFailed(err) => write!(f, "cargo metadata failed: {}", err), | ||
48 | Self::RustcCfgError => write!(f, "failed to get rustc cfgs"), | ||
49 | Self::SysrootNotFound => write!(f, "failed to locate sysroot"), | ||
50 | Self::CargoTomlNotFound(path) => { | ||
51 | write!(f, "can't find Cargo.toml at {}", path.display()) | ||
52 | } | ||
53 | Self::NoStdLib(sysroot) => write!( | ||
54 | f, | ||
55 | "can't load standard library from sysroot\n\ | ||
56 | {:?}\n\ | ||
57 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", | ||
58 | sysroot, | ||
59 | ), | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | impl std::error::Error for WorkspaceError {} | ||
65 | |||
66 | impl From<ParseEditionError> for WorkspaceError { | ||
67 | fn from(err: ParseEditionError) -> Self { | ||
68 | Self::ParseEditionError(err.into()) | ||
69 | } | ||
70 | } | ||
71 | |||
72 | impl From<cargo_metadata::Error> for WorkspaceError { | ||
73 | fn from(err: cargo_metadata::Error) -> Self { | ||
74 | Self::CargoMetadataFailed(err.into()) | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #[derive(Debug, Clone)] | 28 | #[derive(Debug, Clone)] |
79 | pub enum ProjectWorkspace { | 29 | pub enum ProjectWorkspace { |
80 | /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. | 30 | /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. |
diff --git a/crates/ra_project_model/src/workspace_error.rs b/crates/ra_project_model/src/workspace_error.rs new file mode 100644 index 000000000..5f7384968 --- /dev/null +++ b/crates/ra_project_model/src/workspace_error.rs | |||
@@ -0,0 +1,57 @@ | |||
1 | //! Workspace-related errors | ||
2 | |||
3 | use std::{error::Error, fmt, io, path::PathBuf, string::FromUtf8Error}; | ||
4 | |||
5 | use ra_db::ParseEditionError; | ||
6 | |||
7 | #[derive(Debug)] | ||
8 | pub enum WorkspaceError { | ||
9 | CargoMetadataFailed(cargo_metadata::Error), | ||
10 | CargoTomlNotFound(PathBuf), | ||
11 | NoStdLib(PathBuf), | ||
12 | OpenWorkspaceError(io::Error), | ||
13 | ParseEditionError(ParseEditionError), | ||
14 | ReadWorkspaceError(serde_json::Error), | ||
15 | RustcCfgError, | ||
16 | RustcError(io::Error), | ||
17 | RustcOutputError(FromUtf8Error), | ||
18 | SysrootNotFound, | ||
19 | } | ||
20 | |||
21 | impl fmt::Display for WorkspaceError { | ||
22 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
23 | match self { | ||
24 | Self::OpenWorkspaceError(err) | Self::RustcError(err) => write!(f, "{}", err), | ||
25 | Self::ParseEditionError(err) => write!(f, "{}", err), | ||
26 | Self::ReadWorkspaceError(err) => write!(f, "{}", err), | ||
27 | Self::RustcOutputError(err) => write!(f, "{}", err), | ||
28 | Self::CargoMetadataFailed(err) => write!(f, "cargo metadata failed: {}", err), | ||
29 | Self::RustcCfgError => write!(f, "failed to get rustc cfgs"), | ||
30 | Self::SysrootNotFound => write!(f, "failed to locate sysroot"), | ||
31 | Self::CargoTomlNotFound(path) => { | ||
32 | write!(f, "can't find Cargo.toml at {}", path.display()) | ||
33 | } | ||
34 | Self::NoStdLib(sysroot) => write!( | ||
35 | f, | ||
36 | "can't load standard library from sysroot\n\ | ||
37 | {:?}\n\ | ||
38 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", | ||
39 | sysroot, | ||
40 | ), | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | impl From<ParseEditionError> for WorkspaceError { | ||
46 | fn from(err: ParseEditionError) -> Self { | ||
47 | Self::ParseEditionError(err.into()) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | impl From<cargo_metadata::Error> for WorkspaceError { | ||
52 | fn from(err: cargo_metadata::Error) -> Self { | ||
53 | Self::CargoMetadataFailed(err.into()) | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl Error for WorkspaceError {} | ||