From f97da4b11c8d38f3bb002407076bf56acba8675b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 25 May 2024 23:06:56 +0200 Subject: [PATCH 1/2] libutil/source-accessor: custom error if source does not exist This allows better error handling by catching this error in particular. --- src/libutil/source-accessor.cc | 2 +- src/libutil/source-accessor.hh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libutil/source-accessor.cc b/src/libutil/source-accessor.cc index 66093d2cc..e797951c7 100644 --- a/src/libutil/source-accessor.cc +++ b/src/libutil/source-accessor.cc @@ -53,7 +53,7 @@ SourceAccessor::Stat SourceAccessor::lstat(const CanonPath & path) if (auto st = maybeLstat(path)) return *st; else - throw Error("path '%s' does not exist", showPath(path)); + throw FileNotFound("path '%s' does not exist", showPath(path)); } void SourceAccessor::setPathDisplay(std::string displayPrefix, std::string displaySuffix) diff --git a/src/libutil/source-accessor.hh b/src/libutil/source-accessor.hh index d7fb0af5f..cc8db01f5 100644 --- a/src/libutil/source-accessor.hh +++ b/src/libutil/source-accessor.hh @@ -29,6 +29,8 @@ enum class SymlinkResolution { Full, }; +MakeError(FileNotFound, Error); + /** * A read-only filesystem abstraction. This is used by the Nix * evaluator and elsewhere for accessing sources in various From ffe6ba69d6a3a290e56a2891d05c91059f4b9e3a Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 23 May 2024 02:52:54 +0200 Subject: [PATCH 2/2] repl: do not crash when tab-completing import errors File not found while importing is not currently caught by the tab-completion handler. Original bug report: https://git.lix.systems/lix-project/lix/issues/340 Fix has been adapted from https://gerrit.lix.systems/c/lix/+/1189 Example crash: $ cat /tmp/foo.nix { someImport = import ./this_file_does_not_exist; } $ ./src/nix/nix repl --file /tmp/foo.nix warning: unknown experimental feature 'repl-flake' Nix 2.23.0pre20240517_dirty Type :? for help. Loading installable ''... Added 1 variables. nix-repl> someImport. --- src/libcmd/repl.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index a069dd52c..e5d3f6f15 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -304,6 +304,8 @@ StringSet NixRepl::completePrefix(const std::string & prefix) // Quietly ignore evaluation errors. } catch (BadURL & e) { // Quietly ignore BadURL flake-related errors. + } catch (FileNotFound & e) { + // Quietly ignore non-existent file beeing `import`-ed. } }