1#[derive(Debug)]
2pub enum Error {
3 PackageNotMember,
4 EngineNotFound(String),
5 FlutterNotFound,
6 DartNotFound,
7 GenSnapshotNotFound,
8 FormatNotSupported,
9 CargoError,
10 FlutterError,
11 NotCalledWithCargo,
12 Which(which::Error),
13 Io(std::io::Error),
14 Toml(toml::de::Error),
15 Utf8(std::str::Utf8Error),
16 Err(failure::Error),
17}
18
19impl std::fmt::Display for Error {
20 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21 match self {
22 Error::PackageNotMember => write!(f, "Package is not a member of the workspace"),
23 Error::FlutterNotFound => write!(f, "Couldn't find flutter sdk"),
24 Error::EngineNotFound(version) => write!(
25 f,
26 r#"We couldn't find the requested engine version '{}'.
27This means that your flutter version is too old or to new.
28
29To update flutter run `flutter upgrade`. If the problem persists the engine
30build has not completed yet. This means you need to manually supply the flutter
31engine version through one of the following methods:
32
33```bash
34export FLUTTER_ENGINE_VERSION = "..."
35```
36
37`Cargo.toml`
38```toml
39[package.metadata.flutter]
40engine_version = "..."
41```
42
43You'll find the available builds on our github releases page [0].
44
45- [0] https://github.com/flutter-rs/engine-builds/releases"#,
46 version,
47 ),
48 Error::DartNotFound => write!(f, "Could't find dart"),
49 Error::GenSnapshotNotFound => write!(f, "Couldn't find gen_snapshot"),
50 Error::FormatNotSupported => write!(f, "Format not supported"),
51 Error::CargoError => write!(f, "Cargo did not exit successfully"),
52 Error::FlutterError => write!(f, "Flutter did not exit successfully"),
53 Error::NotCalledWithCargo => {
54 write!(f, "This binary may only be called via `cargo flutter`.")
55 }
56 Error::Which(error) => error.fmt(f),
57 Error::Io(error) => error.fmt(f),
58 Error::Toml(error) => error.fmt(f),
59 Error::Utf8(error) => error.fmt(f),
60 Error::Err(error) => error.fmt(f),
61 }
62 }
63}
64
65impl std::error::Error for Error {}
66
67impl From<which::Error> for Error {
68 fn from(error: which::Error) -> Self {
69 Error::Which(error)
70 }
71}
72
73impl From<std::io::Error> for Error {
74 fn from(error: std::io::Error) -> Self {
75 Error::Io(error)
76 }
77}
78
79impl From<toml::de::Error> for Error {
80 fn from(error: toml::de::Error) -> Self {
81 Error::Toml(error)
82 }
83}
84
85impl From<std::str::Utf8Error> for Error {
86 fn from(error: std::str::Utf8Error) -> Self {
87 Error::Utf8(error)
88 }
89}
90
91impl From<failure::Error> for Error {
92 fn from(error: failure::Error) -> Self {
93 Error::Err(error)
94 }
95}