aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authorWilco Kusee <[email protected]>2020-01-03 13:10:50 +0000
committerWilco Kusee <[email protected]>2020-01-03 13:34:16 +0000
commit6c321d7318b94ee93dc60dc88d1e68afa94e8c4f (patch)
tree959822979e426fc98b20e86f6183ace49a16656f /crates/ra_project_model/src
parent2202891221647c9c1a1c6bd47c0b0214b364803d (diff)
Move error to new file
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/lib.rs58
-rw-r--r--crates/ra_project_model/src/workspace_error.rs57
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 @@
3mod cargo_workspace; 3mod cargo_workspace;
4mod json_project; 4mod json_project;
5mod sysroot; 5mod sysroot;
6mod workspace_error;
6 7
7use std::{ 8use 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
15use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
16use ra_db::{CrateGraph, CrateId, Edition, Env, FileId, ParseEditionError}; 16use ra_db::{CrateGraph, CrateId, Edition, Env, FileId};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18use serde_json::from_reader; 18use serde_json::from_reader;
19 19
20use crate::workspace_error::WorkspaceError;
21
20pub use crate::{ 22pub 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)]
27pub 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
40impl 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
64impl std::error::Error for WorkspaceError {}
65
66impl From<ParseEditionError> for WorkspaceError {
67 fn from(err: ParseEditionError) -> Self {
68 Self::ParseEditionError(err.into())
69 }
70}
71
72impl 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)]
79pub enum ProjectWorkspace { 29pub 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
3use std::{error::Error, fmt, io, path::PathBuf, string::FromUtf8Error};
4
5use ra_db::ParseEditionError;
6
7#[derive(Debug)]
8pub 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
21impl 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
45impl From<ParseEditionError> for WorkspaceError {
46 fn from(err: ParseEditionError) -> Self {
47 Self::ParseEditionError(err.into())
48 }
49}
50
51impl From<cargo_metadata::Error> for WorkspaceError {
52 fn from(err: cargo_metadata::Error) -> Self {
53 Self::CargoMetadataFailed(err.into())
54 }
55}
56
57impl Error for WorkspaceError {}