rem_extract/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::fmt;
use std::io;
use syn::Error as SynError;
use ra_ap_ide_assists::Assist;
use ra_ap_vfs::VfsPath;

#[derive(Debug)]
pub enum ExtractionError {
    Io(io::Error),
    Parse(SynError),
    InvalidManifest,
    InvalidStartIdx,
    InvalidEndIdx,
    SameIdx,
    InvalidIdxPair,
    NoExtractFunction(Vec<Assist>),
    ControlFlowFixupFailed(VfsPath),
    CommentNotApplicable,
    BracesNotApplicable,

}

impl fmt::Display for ExtractionError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ExtractionError::Io(e) => write!(f, "I/O error: {}", e),
            ExtractionError::Parse(e) => write!(f, "Parse error: {}", e),
            ExtractionError::InvalidManifest => write!(f, "Could not find a manifest file for the given path"),
            ExtractionError::InvalidStartIdx => write!(f, "Invalid start index"),
            ExtractionError::InvalidEndIdx => write!(f, "Invalid end index"),
            ExtractionError::SameIdx => write!(f, "Start and end indices are the same"),
            ExtractionError::InvalidIdxPair => write!(f, "Invalid pair of start and end indices"),
            ExtractionError::NoExtractFunction(assists) => write!(f, "No Extract Function Assist found for the given selection of assists {:?}", assists),
            ExtractionError::ControlFlowFixupFailed(path) => write!(f, "Control Flow Fixup failed for file {:?}", path),
            ExtractionError::CommentNotApplicable => write!(f, "Extraction not applicable for comment"),
            ExtractionError::BracesNotApplicable => write!(f, "Extraction not applicable for braces"),
        }
    }
}

impl From<io::Error> for ExtractionError {
    fn from(error: io::Error) -> Self {
        ExtractionError::Io(error)
    }
}

impl From<SynError> for ExtractionError {
    fn from(error: SynError) -> Self {
        ExtractionError::Parse(error)
    }
}