mirror of
https://github.com/denoland/deno.git
synced 2024-12-31 03:29:10 -05:00
fix some unwrap() in Rust (#5485)
This commit is contained in:
parent
59cb3c14c7
commit
0b9942da84
5 changed files with 63 additions and 64 deletions
|
@ -107,14 +107,15 @@ fn format_message(
|
||||||
level: usize,
|
level: usize,
|
||||||
) -> String {
|
) -> String {
|
||||||
debug!("format_message");
|
debug!("format_message");
|
||||||
if message_chain.is_none() {
|
|
||||||
return format!("{:indent$}{}", "", message, indent = level);
|
if let Some(message_chain) = message_chain {
|
||||||
|
let mut s = message_chain.format_message(level);
|
||||||
|
s.pop();
|
||||||
|
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
format!("{:indent$}{}", "", message, indent = level)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = message_chain.clone().unwrap().format_message(level);
|
|
||||||
s.pop();
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats optional source, line and column numbers into a single string.
|
/// Formats optional source, line and column numbers into a single string.
|
||||||
|
@ -146,26 +147,28 @@ fn format_maybe_related_information(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let related_information = related_information.clone().unwrap();
|
|
||||||
for rd in related_information {
|
if let Some(related_information) = related_information {
|
||||||
s.push_str("\n\n");
|
for rd in related_information {
|
||||||
s.push_str(&format_stack(
|
s.push_str("\n\n");
|
||||||
match rd.category {
|
s.push_str(&format_stack(
|
||||||
DiagnosticCategory::Error => true,
|
match rd.category {
|
||||||
_ => false,
|
DiagnosticCategory::Error => true,
|
||||||
},
|
_ => false,
|
||||||
format_message(&rd.message_chain, &rd.message, 0),
|
},
|
||||||
rd.source_line.clone(),
|
format_message(&rd.message_chain, &rd.message, 0),
|
||||||
rd.start_column,
|
rd.source_line.clone(),
|
||||||
rd.end_column,
|
rd.start_column,
|
||||||
// Formatter expects 1-based line and column numbers, but ours are 0-based.
|
rd.end_column,
|
||||||
&[format_maybe_frame(
|
// Formatter expects 1-based line and column numbers, but ours are 0-based.
|
||||||
rd.script_resource_name.clone(),
|
&[format_maybe_frame(
|
||||||
rd.line_number.map(|n| n + 1),
|
rd.script_resource_name.clone(),
|
||||||
rd.start_column.map(|n| n + 1),
|
rd.line_number.map(|n| n + 1),
|
||||||
)],
|
rd.start_column.map(|n| n + 1),
|
||||||
4,
|
)],
|
||||||
));
|
4,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s
|
s
|
||||||
|
@ -222,8 +225,8 @@ impl DiagnosticMessageChain {
|
||||||
s.push_str(&std::iter::repeat(" ").take(level * 2).collect::<String>());
|
s.push_str(&std::iter::repeat(" ").take(level * 2).collect::<String>());
|
||||||
s.push_str(&self.message);
|
s.push_str(&self.message);
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
if self.next.is_some() {
|
if let Some(next) = &self.next {
|
||||||
let arr = self.next.clone().unwrap();
|
let arr = next.clone();
|
||||||
for dm in arr {
|
for dm in arr {
|
||||||
s.push_str(&dm.format_message(level + 1));
|
s.push_str(&dm.format_message(level + 1));
|
||||||
}
|
}
|
||||||
|
|
56
cli/flags.rs
56
cli/flags.rs
|
@ -1173,16 +1173,15 @@ fn reload_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reload_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
fn reload_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
||||||
if matches.is_present("reload") {
|
if let Some(cache_bl) = matches.values_of("reload") {
|
||||||
if matches.value_of("reload").is_some() {
|
let raw_cache_blacklist: Vec<String> =
|
||||||
let cache_bl = matches.values_of("reload").unwrap();
|
cache_bl.map(std::string::ToString::to_string).collect();
|
||||||
let raw_cache_blacklist: Vec<String> =
|
if raw_cache_blacklist.is_empty() {
|
||||||
cache_bl.map(std::string::ToString::to_string).collect();
|
flags.reload = true;
|
||||||
|
} else {
|
||||||
flags.cache_blacklist = resolve_urls(raw_cache_blacklist);
|
flags.cache_blacklist = resolve_urls(raw_cache_blacklist);
|
||||||
debug!("cache blacklist: {:#?}", &flags.cache_blacklist);
|
debug!("cache blacklist: {:#?}", &flags.cache_blacklist);
|
||||||
flags.reload = false;
|
flags.reload = false;
|
||||||
} else {
|
|
||||||
flags.reload = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1235,39 +1234,40 @@ fn no_remote_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
if matches.is_present("allow-read") {
|
if let Some(read_wl) = matches.values_of("allow-read") {
|
||||||
if matches.value_of("allow-read").is_some() {
|
let raw_read_whitelist: Vec<PathBuf> = read_wl.map(PathBuf::from).collect();
|
||||||
let read_wl = matches.values_of("allow-read").unwrap();
|
|
||||||
let raw_read_whitelist: Vec<PathBuf> =
|
if raw_read_whitelist.is_empty() {
|
||||||
read_wl.map(PathBuf::from).collect();
|
flags.allow_read = true;
|
||||||
|
} else {
|
||||||
flags.read_whitelist = resolve_fs_whitelist(&raw_read_whitelist);
|
flags.read_whitelist = resolve_fs_whitelist(&raw_read_whitelist);
|
||||||
debug!("read whitelist: {:#?}", &flags.read_whitelist);
|
debug!("read whitelist: {:#?}", &flags.read_whitelist);
|
||||||
} else {
|
|
||||||
flags.allow_read = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if matches.is_present("allow-write") {
|
|
||||||
if matches.value_of("allow-write").is_some() {
|
if let Some(write_wl) = matches.values_of("allow-write") {
|
||||||
let write_wl = matches.values_of("allow-write").unwrap();
|
let raw_write_whitelist: Vec<PathBuf> =
|
||||||
let raw_write_whitelist: Vec<PathBuf> =
|
write_wl.map(PathBuf::from).collect();
|
||||||
write_wl.map(PathBuf::from).collect();
|
|
||||||
|
if raw_write_whitelist.is_empty() {
|
||||||
|
flags.allow_write = true;
|
||||||
|
} else {
|
||||||
flags.write_whitelist = resolve_fs_whitelist(&raw_write_whitelist);
|
flags.write_whitelist = resolve_fs_whitelist(&raw_write_whitelist);
|
||||||
debug!("write whitelist: {:#?}", &flags.write_whitelist);
|
debug!("write whitelist: {:#?}", &flags.write_whitelist);
|
||||||
} else {
|
|
||||||
flags.allow_write = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if matches.is_present("allow-net") {
|
|
||||||
if matches.value_of("allow-net").is_some() {
|
if let Some(net_wl) = matches.values_of("allow-net") {
|
||||||
let net_wl = matches.values_of("allow-net").unwrap();
|
let raw_net_whitelist: Vec<String> =
|
||||||
let raw_net_whitelist =
|
net_wl.map(std::string::ToString::to_string).collect();
|
||||||
net_wl.map(std::string::ToString::to_string).collect();
|
if raw_net_whitelist.is_empty() {
|
||||||
|
flags.allow_net = true;
|
||||||
|
} else {
|
||||||
flags.net_whitelist = resolve_hosts(raw_net_whitelist);
|
flags.net_whitelist = resolve_hosts(raw_net_whitelist);
|
||||||
debug!("net whitelist: {:#?}", &flags.net_whitelist);
|
debug!("net whitelist: {:#?}", &flags.net_whitelist);
|
||||||
} else {
|
|
||||||
flags.allow_net = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.is_present("allow-env") {
|
if matches.is_present("allow-env") {
|
||||||
flags.allow_env = true;
|
flags.allow_env = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,9 +291,7 @@ impl TlsListenerResource {
|
||||||
/// Stop tracking a task.
|
/// Stop tracking a task.
|
||||||
/// Happens when the task is done and thus no further tracking is needed.
|
/// Happens when the task is done and thus no further tracking is needed.
|
||||||
pub fn untrack_task(&mut self) {
|
pub fn untrack_task(&mut self) {
|
||||||
if self.waker.is_some() {
|
self.waker.take();
|
||||||
self.waker.take();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -529,8 +529,7 @@ impl Future for CoreIsolate {
|
||||||
assert_eq!(inner.shared.size(), 0);
|
assert_eq!(inner.shared.size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if overflow_response.is_some() {
|
if let Some((op_id, buf)) = overflow_response.take() {
|
||||||
let (op_id, buf) = overflow_response.take().unwrap();
|
|
||||||
async_op_response(
|
async_op_response(
|
||||||
scope,
|
scope,
|
||||||
Some((op_id, buf)),
|
Some((op_id, buf)),
|
||||||
|
|
|
@ -261,8 +261,7 @@ fn format_source_loc(
|
||||||
|
|
||||||
impl fmt::Display for JSError {
|
impl fmt::Display for JSError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if self.script_resource_name.is_some() {
|
if let Some(script_resource_name) = &self.script_resource_name {
|
||||||
let script_resource_name = self.script_resource_name.as_ref().unwrap();
|
|
||||||
if self.line_number.is_some() && self.start_column.is_some() {
|
if self.line_number.is_some() && self.start_column.is_some() {
|
||||||
assert!(self.line_number.is_some());
|
assert!(self.line_number.is_some());
|
||||||
assert!(self.start_column.is_some());
|
assert!(self.start_column.is_some());
|
||||||
|
|
Loading…
Reference in a new issue