diff options
author | Simon Garrelou <simon.garrelou@gmail.com> | 2023-07-07 18:32:54 +0200 |
---|---|---|
committer | Simon Garrelou <simon.garrelou@gmail.com> | 2023-07-07 23:13:58 +0200 |
commit | 1d43cd353641825865f279d79179447c3e06be08 (patch) | |
tree | b46b542bdce8d89bc60cfa7dd86f44653698e6c8 | |
parent | 7440861a60faf0ca7dd448559b7f11f0d3b87e2f (diff) | |
download | rss-1d43cd353641825865f279d79179447c3e06be08.tar.gz rss-1d43cd353641825865f279d79179447c3e06be08.zip |
Improve error handling
-rw-r--r-- | src/main.rs | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 0ee259c..2c53729 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -41,11 +41,11 @@ enum Commands { | |||
41 | #[arg(short='v', long)] | 41 | #[arg(short='v', long)] |
42 | invert_match: bool, | 42 | invert_match: bool, |
43 | 43 | ||
44 | // Keep only items whose link contain this substring | 44 | // Keep only items whose link contains this substring |
45 | #[arg(short, long)] | 45 | #[arg(short, long)] |
46 | url: Option<String>, | 46 | url: Option<String>, |
47 | 47 | ||
48 | // Keep only items whose title contain this substring | 48 | // Keep only items whose title contains this substring |
49 | #[arg(short, long)] | 49 | #[arg(short, long)] |
50 | title: Option<String>, | 50 | title: Option<String>, |
51 | 51 | ||
@@ -82,8 +82,7 @@ fn main() { | |||
82 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | 82 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); |
83 | }, | 83 | }, |
84 | Err(e) => { | 84 | Err(e) => { |
85 | eprintln!("Error running 'get': {:?}", e); | 85 | crash_and_burn(&e); |
86 | exit(1); | ||
87 | } | 86 | } |
88 | } | 87 | } |
89 | }, | 88 | }, |
@@ -102,14 +101,12 @@ fn main() { | |||
102 | sorted.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | 101 | sorted.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); |
103 | }, | 102 | }, |
104 | Err(e) => { | 103 | Err(e) => { |
105 | eprintln!("Error with 'sort': {:?}", e); | 104 | crash_and_burn(&e); |
106 | exit(1); | ||
107 | } | 105 | } |
108 | } | 106 | } |
109 | }, | 107 | }, |
110 | Err(e) => { | 108 | Err(e) => { |
111 | eprintln!("sort: could not parse RSS: {:?}", e); | 109 | crash_and_burn(&e); |
112 | exit(1); | ||
113 | } | 110 | } |
114 | } | 111 | } |
115 | }, | 112 | }, |
@@ -122,14 +119,12 @@ fn main() { | |||
122 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | 119 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); |
123 | }, | 120 | }, |
124 | Err(e) => { | 121 | Err(e) => { |
125 | eprintln!("Error with 'take': {:?}", e); | 122 | crash_and_burn(&e); |
126 | exit(1); | ||
127 | } | 123 | } |
128 | } | 124 | } |
129 | }, | 125 | }, |
130 | Err(e) => { | 126 | Err(e) => { |
131 | eprintln!("take: could not parse RSS: {:?}", e); | 127 | crash_and_burn(&e); |
132 | exit(1); | ||
133 | } | 128 | } |
134 | } | 129 | } |
135 | }, | 130 | }, |
@@ -142,14 +137,12 @@ fn main() { | |||
142 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | 137 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); |
143 | }, | 138 | }, |
144 | Err(e) => { | 139 | Err(e) => { |
145 | eprintln!("Error with 'filter': {:?}", e); | 140 | crash_and_burn(&e); |
146 | exit(1); | ||
147 | } | 141 | } |
148 | } | 142 | } |
149 | }, | 143 | }, |
150 | Err(e) => { | 144 | Err(e) => { |
151 | eprintln!("filter: could not parse RSS: {:?}", e); | 145 | crash_and_burn(&e); |
152 | exit(1); | ||
153 | } | 146 | } |
154 | } | 147 | } |
155 | }, | 148 | }, |
@@ -162,16 +155,32 @@ fn main() { | |||
162 | print!("{}", t); | 155 | print!("{}", t); |
163 | }, | 156 | }, |
164 | Err(e) => { | 157 | Err(e) => { |
165 | eprintln!("Error with 'render': {:?}", e); | 158 | crash_and_burn(&e); |
166 | exit(1); | ||
167 | } | 159 | } |
168 | } | 160 | } |
169 | }, | 161 | }, |
170 | Err(e) => { | 162 | Err(e) => { |
171 | eprintln!("render: could not parse RSS: {:?}", e); | 163 | crash_and_burn(&e); |
172 | exit(1); | ||
173 | } | 164 | } |
174 | } | 165 | } |
175 | } | 166 | } |
176 | } | 167 | } |
177 | } | 168 | } |
169 | |||
170 | fn command_line_args() -> Vec<String> { | ||
171 | let mut v: Vec<String> = vec![]; | ||
172 | |||
173 | for a in std::env::args().into_iter() { | ||
174 | v.push(a); | ||
175 | } | ||
176 | |||
177 | v | ||
178 | } | ||
179 | |||
180 | fn crash_and_burn<T: std::fmt::Debug>(err: &T) { | ||
181 | let cmdline = command_line_args().join(" "); | ||
182 | eprintln!("Error with command: {}", cmdline); | ||
183 | eprintln!("Details:\n\n{:?}", err); | ||
184 | |||
185 | exit(1); | ||
186 | } \ No newline at end of file | ||