From 0068e91aad6908c9574d96fced9c599328dd2391 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 3 Oct 2023 21:50:32 +0100 Subject: [PATCH] open: Display a meaningful error if the specified file doesn't exist Previously, the error given for any non-existent file was: "Failed to open ':'". --- Userland/Utilities/open.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Userland/Utilities/open.cpp b/Userland/Utilities/open.cpp index 11cedb6c71..4ba569830c 100644 --- a/Userland/Utilities/open.cpp +++ b/Userland/Utilities/open.cpp @@ -25,8 +25,17 @@ ErrorOr serenity_main(Main::Arguments arguments) bool all_ok = true; for (auto& url_or_path : urls_or_paths) { - auto path = FileSystem::real_path(url_or_path); - auto url = URL::create_with_url_or_path(path.is_error() ? url_or_path : path.value()); + auto path_or_error = FileSystem::real_path(url_or_path); + URL url; + if (path_or_error.is_error()) { + url = url_or_path; + if (!url.is_valid()) { + warnln("Failed to open: '{}': {}", url_or_path, strerror(path_or_error.error().code())); + continue; + } + } else { + url = URL::create_with_url_or_path(path_or_error.value().to_deprecated_string()); + } if (!Desktop::Launcher::open(url)) { warnln("Failed to open '{}'", url);