1use std::error::Error as StdError;
2use std::fmt;
3use std::io;
4use syn::Error as SynError;
5use ra_ap_ide_assists::Assist;
6
7#[derive(Debug)]
8pub enum ExtractionError {
9 Io(io::Error),
10 Parse(SynError),
11 InvalidManifest,
12 InvalidStartIdx,
13 InvalidEndIdx,
14 SameIdx,
15 InvalidIdxPair,
16 NoExtractFunction(Vec<Assist>),
17 CommentNotApplicable,
18 BracesNotApplicable,
19 ParentMethodNotFound,
20}
21
22impl fmt::Display for ExtractionError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 ExtractionError::Io(e) => write!(f, "I/O error: {}", e),
26 ExtractionError::Parse(e) => write!(f, "Parse error: {}", e),
27 ExtractionError::InvalidManifest => write!(f, "Could not find a manifest file for the given path"),
28 ExtractionError::InvalidStartIdx => write!(f, "Invalid start index"),
29 ExtractionError::InvalidEndIdx => write!(f, "Invalid end index"),
30 ExtractionError::SameIdx => write!(f, "Start and end indices are the same"),
31 ExtractionError::InvalidIdxPair => write!(f, "Invalid pair of start and end indices"),
32 ExtractionError::NoExtractFunction(assists) =>
33 write!(f, "No Extract Function Assist found for the given selection of assists {:?}", assists),
34 ExtractionError::CommentNotApplicable => write!(f, "Extraction not applicable for comment"),
35 ExtractionError::BracesNotApplicable => write!(f, "Extraction not applicable for braces"),
36 ExtractionError::ParentMethodNotFound => write!(f, "Parent method not found"),
37 }
38 }
39}
40
41impl StdError for ExtractionError {
43 fn source(&self) -> Option<&(dyn StdError + 'static)> {
44 match self {
45 ExtractionError::Io(e) => Some(e),
46 ExtractionError::Parse(e) => Some(e),
47 _ => None,
48 }
49 }
50}
51
52impl From<io::Error> for ExtractionError {
53 fn from(e: io::Error) -> Self { ExtractionError::Io(e) }
54}
55impl From<SynError> for ExtractionError {
56 fn from(e: SynError) -> Self { ExtractionError::Parse(e) }
57}