Browse Source

Use Display trait for more readable error messages

Johannes Hofmann 7 years ago
parent
commit
b26ef4c333
1 changed files with 17 additions and 6 deletions
  1. 17
    6
      src/main.rs

+ 17
- 6
src/main.rs View File

29
 use coord::ScreenCoord;
29
 use coord::ScreenCoord;
30
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
30
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
31
 use map_view_gl::MapViewGl;
31
 use map_view_gl::MapViewGl;
32
+use std::error::Error;
32
 use std::time::{Duration, Instant};
33
 use std::time::{Duration, Instant};
33
 use tile_source::TileSource;
34
 use tile_source::TileSource;
34
 
35
 
174
     dur.as_secs() as f64 + f64::from(dur.subsec_nanos()) * 1e-9
175
     dur.as_secs() as f64 + f64::from(dur.subsec_nanos()) * 1e-9
175
 }
176
 }
176
 
177
 
177
-fn main() {
178
-    env_logger::init();
179
-
180
-    let config = config::Config::from_arg_matches(&args::parse()).unwrap();
178
+fn run() -> Result<(), Box<Error>> {
179
+    let config = config::Config::from_arg_matches(&args::parse())?;
181
 
180
 
182
-    let mut sources = TileSources::new(config.tile_sources()).unwrap();
181
+    let mut sources = TileSources::new(config.tile_sources())
182
+        .ok_or_else(|| "no tile sources provided.")?;
183
 
183
 
184
     let mut events_loop = glutin::EventsLoop::new();
184
     let mut events_loop = glutin::EventsLoop::new();
185
     let builder = glutin::WindowBuilder::new()
185
     let builder = glutin::WindowBuilder::new()
186
         .with_title(format!("DeltaMap - {}", sources.current_name()));
186
         .with_title(format!("DeltaMap - {}", sources.current_name()));
187
 
187
 
188
     let gl_context = glutin::ContextBuilder::new();
188
     let gl_context = glutin::ContextBuilder::new();
189
-    let gl_window = glutin::GlWindow::new(builder, gl_context, &events_loop).unwrap();
189
+    let gl_window = glutin::GlWindow::new(builder, gl_context, &events_loop)?;
190
     let window = gl_window.window();
190
     let window = gl_window.window();
191
 
191
 
192
     let _ = unsafe { gl_window.make_current() };
192
     let _ = unsafe { gl_window.make_current() };
320
             window.set_title(&format!("DeltaMap - {}", sources.current_name()));
320
             window.set_title(&format!("DeltaMap - {}", sources.current_name()));
321
         }
321
         }
322
     }
322
     }
323
+
324
+    Ok(())
325
+}
326
+
327
+fn main() {
328
+    env_logger::init();
329
+
330
+    if let Err(err) = run() {
331
+        println!("{}", err);
332
+        std::process::exit(1);
333
+    }
323
 }
334
 }
324
 
335
 
325
 struct TileSources<'a> {
336
 struct TileSources<'a> {