Give a better error message in case of unlocked inputs

This commit is contained in:
Eelco Dolstra 2022-06-02 16:15:57 +02:00
parent 1395210a68
commit 1c7d0b716d
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 8 additions and 6 deletions

View file

@ -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);

View file

@ -197,7 +197,7 @@ void LockFile::write(const Path & path) const
writeFile(path, fmt("%s\n", *this));
}
bool LockFile::isLocked() const
std::optional<FlakeRef> LockFile::isUnlocked() const
{
std::unordered_set<std::shared_ptr<const Node>> 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

View file

@ -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<FlakeRef> isUnlocked() const;
bool operator ==(const LockFile & other) const;