From 349af05da8a069e6f3be61b92e2736062630fbc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Mon, 20 Sep 2021 21:44:47 +0300 Subject: [PATCH] Do not throw error for files not found in lib_dirs (#4029) --- .../nu-command/src/commands/core_commands/source.rs | 12 +++++------- crates/nu-parser/src/parse/source.rs | 11 +++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/crates/nu-command/src/commands/core_commands/source.rs b/crates/nu-command/src/commands/core_commands/source.rs index 3926645628..f779015727 100644 --- a/crates/nu-command/src/commands/core_commands/source.rs +++ b/crates/nu-command/src/commands/core_commands/source.rs @@ -69,13 +69,11 @@ pub fn source(args: CommandArgs) -> Result { for lib_path in dir { match lib_path { Ok(name) => { - let path = canonicalize_with(&source_file, name).map_err(|e| { - ShellError::labeled_error( - format!("Can't load source file. Reason: {}", e.to_string()), - "Can't load this file", - filename.span(), - ) - })?; + let path = if let Ok(p) = canonicalize_with(&source_file, name) { + p + } else { + continue; + }; if let Ok(contents) = std::fs::read_to_string(path) { let result = script::run_script_standalone(contents, true, ctx, false); diff --git a/crates/nu-parser/src/parse/source.rs b/crates/nu-parser/src/parse/source.rs index 1ff41b8cbf..0871bf8ab5 100644 --- a/crates/nu-parser/src/parse/source.rs +++ b/crates/nu-parser/src/parse/source.rs @@ -61,12 +61,11 @@ fn find_source_file( if let Some(dir) = lib_dirs { for lib_path in dir.into_iter().flatten() { - let path = canonicalize_with(&file, lib_path).map_err(|e| { - ParseError::general_error( - format!("Can't load source file. Reason: {}", e.to_string()), - "Can't load this file".spanned(file_span), - ) - })?; + let path = if let Ok(p) = canonicalize_with(&file, lib_path) { + p + } else { + continue; + }; if let Ok(contents) = std::fs::read_to_string(&path) { return parse(&contents, 0, scope);