Improve display of GitHub input filenames in error messages

E.g.

  … while evaluating the attribute 'buildCommand' of the derivation 'vm-test-run-github-flakes'

  at «github:NixOS/nixpkgs/2fa57ed190fd6c7c746319444f34b5917666e5c1»/pkgs/stdenv/generic/make-derivation.nix:278:7:
This commit is contained in:
Eelco Dolstra 2022-07-14 16:51:54 +02:00
parent 9a9b03b8d6
commit e17a619106
4 changed files with 24 additions and 9 deletions

View file

@ -496,6 +496,8 @@ EvalState::EvalState(
, baseEnv(allocEnv(128)) , baseEnv(allocEnv(128))
, staticBaseEnv{std::make_shared<StaticEnv>(false, nullptr)} , staticBaseEnv{std::make_shared<StaticEnv>(false, nullptr)}
{ {
corepkgsFS->setPathDisplay("<nix", ">");
countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0"; countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";
assert(gcInitialised); assert(gcInitialised);

View file

@ -232,7 +232,11 @@ struct GitArchiveInputScheme : InputScheme
{ {
auto [storePath, input2] = downloadArchive(store, input); auto [storePath, input2] = downloadArchive(store, input);
return {makeZipInputAccessor(CanonPath(store->toRealPath(storePath))), input2}; auto accessor = makeZipInputAccessor(CanonPath(store->toRealPath(storePath)));
accessor->setPathDisplay("«" + input2.to_string() + "»");
return {accessor, input2};
} }
}; };

View file

@ -9,7 +9,9 @@ static std::atomic<size_t> nextNumber{0};
InputAccessor::InputAccessor() InputAccessor::InputAccessor()
: number(++nextNumber) : number(++nextNumber)
{ } , displayPrefix{"/virtual/" + std::to_string(number)}
{
}
// FIXME: merge with archive.cc. // FIXME: merge with archive.cc.
void InputAccessor::dumpPath( void InputAccessor::dumpPath(
@ -91,9 +93,15 @@ std::optional<InputAccessor::Stat> InputAccessor::maybeLstat(const CanonPath & p
return lstat(path); return lstat(path);
} }
void InputAccessor::setPathDisplay(std::string displayPrefix, std::string displaySuffix)
{
this->displayPrefix = std::move(displayPrefix);
this->displaySuffix = std::move(displaySuffix);
}
std::string InputAccessor::showPath(const CanonPath & path) std::string InputAccessor::showPath(const CanonPath & path)
{ {
return "/virtual/" + std::to_string(number) + path.abs(); return displayPrefix + path.abs() + displaySuffix;
} }
struct FSInputAccessorImpl : FSInputAccessor struct FSInputAccessorImpl : FSInputAccessor
@ -109,7 +117,9 @@ struct FSInputAccessorImpl : FSInputAccessor
: root(root) : root(root)
, allowedPaths(std::move(allowedPaths)) , allowedPaths(std::move(allowedPaths))
, makeNotAllowedError(std::move(makeNotAllowedError)) , makeNotAllowedError(std::move(makeNotAllowedError))
{ } {
displayPrefix = root.abs();
}
std::string readFile(const CanonPath & path) override std::string readFile(const CanonPath & path) override
{ {
@ -201,11 +211,6 @@ struct FSInputAccessorImpl : FSInputAccessor
{ {
return (bool) allowedPaths; return (bool) allowedPaths;
} }
std::string showPath(const CanonPath & path) override
{
return (root + path).abs();
}
}; };
ref<FSInputAccessor> makeFSInputAccessor( ref<FSInputAccessor> makeFSInputAccessor(

View file

@ -13,6 +13,8 @@ struct InputAccessor : public std::enable_shared_from_this<InputAccessor>
{ {
const size_t number; const size_t number;
std::string displayPrefix, displaySuffix;
InputAccessor(); InputAccessor();
virtual ~InputAccessor() virtual ~InputAccessor()
@ -58,6 +60,8 @@ struct InputAccessor : public std::enable_shared_from_this<InputAccessor>
return number < x.number; return number < x.number;
} }
void setPathDisplay(std::string displayPrefix, std::string displaySuffix = "");
virtual std::string showPath(const CanonPath & path); virtual std::string showPath(const CanonPath & path);
}; };