Give a useful error when passed a non-existant file

This commit is contained in:
Matt Brubeck 2015-06-04 11:16:47 -07:00
parent 0bbc28236a
commit 76cf5bb45a
2 changed files with 11 additions and 3 deletions

View file

@ -8,7 +8,7 @@
#![feature(core)] #![feature(core)]
#![feature(exit_status)] #![feature(exit_status)]
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![cfg_attr(not(target_os = "android"), feature(path_ext))] #![feature(path_ext)]
#![feature(plugin)] #![feature(plugin)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(step_by)] #![feature(step_by)]

View file

@ -16,7 +16,9 @@ use std::collections::HashSet;
use std::cmp; use std::cmp;
use std::env; use std::env;
use std::io::{self, Write}; use std::io::{self, Write};
use std::fs::PathExt;
use std::mem; use std::mem;
use std::path::Path;
use std::ptr; use std::ptr;
use url::{self, Url}; use url::{self, Url};
@ -310,8 +312,14 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
let cwd = env::current_dir().unwrap(); let cwd = env::current_dir().unwrap();
match Url::parse(url) { match Url::parse(url) {
Ok(url) => url, Ok(url) => url,
Err(url::ParseError::RelativeUrlWithoutBase) Err(url::ParseError::RelativeUrlWithoutBase) => {
=> Url::from_file_path(&*cwd.join(url)).unwrap(), if Path::new(url).exists() {
Url::from_file_path(&*cwd.join(url)).unwrap()
} else {
args_fail(&format!("File not found: {}", url));
return false;
}
}
Err(_) => panic!("URL parsing failed"), Err(_) => panic!("URL parsing failed"),
} }
}; };