Browse Source

Use Display trait for printing errors

...instead of using the `description` method.
Johannes Hofmann 7 years ago
parent
commit
a6c0ea8561
4 changed files with 12 additions and 16 deletions
  1. 4
    5
      src/config.rs
  2. 1
    2
      src/main.rs
  3. 4
    5
      src/program.rs
  4. 3
    4
      src/tile_loader.rs

+ 4
- 5
src/config.rs View File

1
-use std::error::Error;
2
 use std::fs::File;
1
 use std::fs::File;
3
 use std::io::{Read, Write};
2
 use std::io::{Read, Write};
4
 use std::path::{Path, PathBuf};
3
 use std::path::{Path, PathBuf};
45
     /// not exist.
44
     /// not exist.
46
     fn default_tile_cache_dir() -> Result<PathBuf, String> {
45
     fn default_tile_cache_dir() -> Result<PathBuf, String> {
47
         let xdg_dirs = xdg::BaseDirectories::with_prefix("deltamap")
46
         let xdg_dirs = xdg::BaseDirectories::with_prefix("deltamap")
48
-            .map_err(|e| e.description().to_string())?;
47
+            .map_err(|e| format!("{}", e))?;
49
 
48
 
50
         match xdg_dirs.find_cache_file("tiles") {
49
         match xdg_dirs.find_cache_file("tiles") {
51
             Some(dir) => Ok(dir),
50
             Some(dir) => Ok(dir),
154
                 )
153
                 )
155
             },
154
             },
156
             Ok(_) => Err("TOML file has invalid structure. Expected a Table as the top-level element.".to_string()),
155
             Ok(_) => Err("TOML file has invalid structure. Expected a Table as the top-level element.".to_string()),
157
-            Err(e) => Err(e.description().to_string()),
156
+            Err(e) => Err(format!("{}", e)),
158
         }
157
         }
159
     }
158
     }
160
 
159
 
161
     pub fn from_toml_file<P: AsRef<Path>>(path: P) -> Result<Config, String> {
160
     pub fn from_toml_file<P: AsRef<Path>>(path: P) -> Result<Config, String> {
162
-        let mut file = File::open(path).map_err(|e| e.description().to_string())?;
161
+        let mut file = File::open(path).map_err(|e| format!("{}", e))?;
163
 
162
 
164
         let mut content = String::new();
163
         let mut content = String::new();
165
-        file.read_to_string(&mut content).map_err(|e| e.description().to_string())?;
164
+        file.read_to_string(&mut content).map_err(|e| format!("{}", e))?;
166
 
165
 
167
         Config::from_toml_str(&content)
166
         Config::from_toml_str(&content)
168
     }
167
     }

+ 1
- 2
src/main.rs View File

30
 use coord::ScreenCoord;
30
 use coord::ScreenCoord;
31
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
31
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
32
 use map_view_gl::MapViewGl;
32
 use map_view_gl::MapViewGl;
33
-use std::error::Error;
34
 use std::time::{Duration, Instant};
33
 use std::time::{Duration, Instant};
35
 use tile_source::TileSource;
34
 use tile_source::TileSource;
36
 
35
 
195
             .validator(|s| {
194
             .validator(|s| {
196
                 s.parse::<f64>()
195
                 s.parse::<f64>()
197
                     .map(|_| ())
196
                     .map(|_| ())
198
-                    .map_err(|e| e.description().to_string())
197
+                    .map_err(|e| format!("{}", e))
199
             })
198
             })
200
             .help("Set target frames per second (default is 60). \
199
             .help("Set target frames per second (default is 60). \
201
                 This should equal the refresh rate of the display.")
200
                 This should equal the refresh rate of the display.")

+ 4
- 5
src/program.rs View File

1
 use ::context;
1
 use ::context;
2
 use context::Context;
2
 use context::Context;
3
-use std::error::Error;
4
 use std::ffi::CStr;
3
 use std::ffi::CStr;
5
 use std::fs::File;
4
 use std::fs::File;
6
 use std::io::BufReader;
5
 use std::io::BufReader;
29
     pub fn from_paths<P: AsRef<Path>>(cx: &'a Context, vert_path: P, frag_path: P) -> Result<Program<'a>, String> {
28
     pub fn from_paths<P: AsRef<Path>>(cx: &'a Context, vert_path: P, frag_path: P) -> Result<Program<'a>, String> {
30
         let vert_src = {
29
         let vert_src = {
31
             let file = File::open(&vert_path)
30
             let file = File::open(&vert_path)
32
-                .map_err(|e| e.description().to_string())?;
31
+                .map_err(|e| format!("{}", e))?;
33
             let mut reader = BufReader::new(file);
32
             let mut reader = BufReader::new(file);
34
             let mut buf: Vec<u8> = vec![];
33
             let mut buf: Vec<u8> = vec![];
35
             reader.read_to_end(&mut buf)
34
             reader.read_to_end(&mut buf)
36
-                .map_err(|e| e.description().to_string())?;
35
+                .map_err(|e| format!("{}", e))?;
37
             buf
36
             buf
38
         };
37
         };
39
 
38
 
40
         let frag_src = {
39
         let frag_src = {
41
             let file = File::open(&frag_path)
40
             let file = File::open(&frag_path)
42
-                .map_err(|e| e.description().to_string())?;
41
+                .map_err(|e| format!("{}", e))?;
43
             let mut reader = BufReader::new(file);
42
             let mut reader = BufReader::new(file);
44
             let mut buf: Vec<u8> = vec![];
43
             let mut buf: Vec<u8> = vec![];
45
             reader.read_to_end(&mut buf)
44
             reader.read_to_end(&mut buf)
46
-                .map_err(|e| e.description().to_string())?;
45
+                .map_err(|e| format!("{}", e))?;
47
             buf
46
             buf
48
         };
47
         };
49
 
48
 

+ 3
- 4
src/tile_loader.rs View File

5
 use std::cmp::Ordering;
5
 use std::cmp::Ordering;
6
 use std::cmp;
6
 use std::cmp;
7
 use std::collections::hash_set::HashSet;
7
 use std::collections::hash_set::HashSet;
8
-use std::error::Error;
9
 use std::fs::File;
8
 use std::fs::File;
10
 use std::io::Write;
9
 use std::io::Write;
11
 use std::path::{Path, PathBuf};
10
 use std::path::{Path, PathBuf};
140
                                         }
139
                                         }
141
                                         if let Err(e) = remote_request_tx.send(RemoteLoaderMessage::PopQueue) {
140
                                         if let Err(e) = remote_request_tx.send(RemoteLoaderMessage::PopQueue) {
142
                                             //TODO what now? restart worker?
141
                                             //TODO what now? restart worker?
143
-                                            error!("remote worker terminated, {}", e.description());
142
+                                            error!("remote worker terminated, {}", e);
144
                                         }
143
                                         }
145
                                     }
144
                                     }
146
                                 } else if result_tx.send((request.tile, None)).is_err() {
145
                                 } else if result_tx.send((request.tile, None)).is_err() {
193
 
192
 
194
                                     if request.write_to_file {
193
                                     if request.write_to_file {
195
                                         if let Err(e) = Self::write_to_file(&request.path, &buf) {
194
                                         if let Err(e) = Self::write_to_file(&request.path, &buf) {
196
-                                            warn!("could not write file {}, {}", request.path.display(), e.description());
195
+                                            warn!("could not write file {}, {}", request.path.display(), e);
197
                                         }
196
                                         }
198
                                     }
197
                                     }
199
 
198
 
282
                                     if write_to_file {
281
                                     if write_to_file {
283
                                         let path = source.local_tile_path(tile);
282
                                         let path = source.local_tile_path(tile);
284
                                         if let Err(e) = Self::write_to_file(&path, &buf) {
283
                                         if let Err(e) = Self::write_to_file(&path, &buf) {
285
-                                            warn!("could not write file {}, {}", &path.display(), e.description());
284
+                                            warn!("could not write file {}, {}", &path.display(), e);
286
                                         }
285
                                         }
287
                                     }
286
                                     }
288
                                     debug!("sync ok from network {:?}", tile);
287
                                     debug!("sync ok from network {:?}", tile);