aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-02 17:33:07 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-09-02 17:35:35 +0200
commit61fdb16aacf9ff18c96b72a37e1b46eb14586eb4 (patch)
treee513ef2858e96d2b9d764c5e9b5fe5b3bec2f250 /src/libexpr/flake
parent5ec2a1ed82d485429aaf6fbad55fd6c1320b2d8c (diff)
Improve error message when a directory is not a flake
So you now get $ nix build error: path '.' is not a flake (because it does not reference a Git repository) rather than $ nix build error: unsupported argument '.'
Diffstat (limited to 'src/libexpr/flake')
-rw-r--r--src/libexpr/flake/flakeref.cc6
-rw-r--r--src/libexpr/flake/flakeref.hh1
2 files changed, 4 insertions, 3 deletions
diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc
index 7631cd53a..253442566 100644
--- a/src/libexpr/flake/flakeref.cc
+++ b/src/libexpr/flake/flakeref.cc
@@ -145,10 +145,10 @@ FlakeRef::FlakeRef(const std::string & uri_, bool allowRelative)
d.path = absPath(uri);
try {
if (!S_ISDIR(lstat(d.path).st_mode))
- throw BadFlakeRef("path '%s' is not a flake (sub)directory");
+ throw MissingFlake("path '%s' is not a flake (sub)directory", d.path);
} catch (SysError & e) {
if (e.errNo == ENOENT || e.errNo == EISDIR)
- throw BadFlakeRef("flake '%s' does not exist");
+ throw MissingFlake("flake '%s' does not exist", d.path);
throw;
}
while (true) {
@@ -156,7 +156,7 @@ FlakeRef::FlakeRef(const std::string & uri_, bool allowRelative)
subdir = baseNameOf(d.path) + (subdir.empty() ? "" : "/" + subdir);
d.path = dirOf(d.path);
if (d.path == "/")
- throw BadFlakeRef("path '%s' does not reference a Git repository", uri);
+ throw MissingFlake("path '%s' is not a flake (because it does not reference a Git repository)", uri);
}
} else
d.path = canonPath(uri);
diff --git a/src/libexpr/flake/flakeref.hh b/src/libexpr/flake/flakeref.hh
index 082dd8c26..9ddc227bb 100644
--- a/src/libexpr/flake/flakeref.hh
+++ b/src/libexpr/flake/flakeref.hh
@@ -187,6 +187,7 @@ struct FlakeRef
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
MakeError(BadFlakeRef, Error);
+MakeError(MissingFlake, BadFlakeRef);
std::optional<FlakeRef> parseFlakeRef(
const std::string & uri, bool allowRelative = false);