From 1c7d0b716d1da05283b6c2cd9ee3e22553c7b0a0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Jun 2022 16:15:57 +0200 Subject: [PATCH] Give a better error message in case of unlocked inputs --- src/libexpr/flake/flake.cc | 4 ++-- src/libexpr/flake/lockfile.cc | 6 +++--- src/libexpr/flake/lockfile.hh | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 658e06342..397ca4743 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -630,9 +630,9 @@ LockedFlake lockFlake( if (lockFlags.writeLockFile) { if (auto sourcePath = topRef.input.getSourcePath()) { - if (!newLockFile.isLocked()) { + if (auto unlockedInput = newLockFile.isUnlocked()) { if (fetchSettings.warnDirty) - warn("will not write lock file of flake '%s' because it has an unlocked input", topRef); + warn("will not write lock file of flake '%s' because it has an unlocked input ('%s')", topRef, *unlockedInput); } else { if (!lockFlags.updateLockFile) throw Error("flake '%s' requires lock file changes but they're not allowed due to '--no-update-lock-file'", topRef); diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index ae67f8e61..7155f7371 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -197,7 +197,7 @@ void LockFile::write(const Path & path) const writeFile(path, fmt("%s\n", *this)); } -bool LockFile::isLocked() const +std::optional LockFile::isUnlocked() const { std::unordered_set> nodes; @@ -219,10 +219,10 @@ bool LockFile::isLocked() const if (node && !node->lockedRef.input.isLocked() && !node->lockedRef.input.isRelative()) - return false; + return node->lockedRef; } - return true; + return {}; } bool LockFile::operator ==(const LockFile & other) const diff --git a/src/libexpr/flake/lockfile.hh b/src/libexpr/flake/lockfile.hh index a4290c9e9..89b449dcf 100644 --- a/src/libexpr/flake/lockfile.hh +++ b/src/libexpr/flake/lockfile.hh @@ -60,7 +60,9 @@ struct LockFile void write(const Path & path) const; - bool isLocked() const; + /* Check whether this lock file has any unlocked inputs. If so, + return one. */ + std::optional isUnlocked() const; bool operator ==(const LockFile & other) const;