mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-11 00:36:20 +02:00
more debug_throw coverage of EvalErrors
This commit is contained in:
parent
3d94d3ba91
commit
eaecaaa00b
5 changed files with 35 additions and 30 deletions
|
@ -506,14 +506,14 @@ std::string AttrCursor::getString()
|
|||
debug("using cached string attribute '%s'", getAttrPathStr());
|
||||
return s->first;
|
||||
} else
|
||||
throw TypeError("'%s' is not a string", getAttrPathStr());
|
||||
root->state.debug_throw(TypeError("'%s' is not a string", getAttrPathStr()));
|
||||
}
|
||||
}
|
||||
|
||||
auto & v = forceValue();
|
||||
|
||||
if (v.type() != nString && v.type() != nPath)
|
||||
throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
|
||||
root->state.debug_throw(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
|
||||
|
||||
return v.type() == nString ? v.string.s : v.path;
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ string_t AttrCursor::getStringWithContext()
|
|||
return *s;
|
||||
}
|
||||
} else
|
||||
throw TypeError("'%s' is not a string", getAttrPathStr());
|
||||
root->state.debug_throw(TypeError("'%s' is not a string", getAttrPathStr()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,7 +548,10 @@ string_t AttrCursor::getStringWithContext()
|
|||
else if (v.type() == nPath)
|
||||
return {v.path, {}};
|
||||
else
|
||||
throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
|
||||
{
|
||||
root->state.debug_throw(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
|
||||
return {v.path, {}}; // should never execute
|
||||
}
|
||||
}
|
||||
|
||||
bool AttrCursor::getBool()
|
||||
|
@ -561,14 +564,14 @@ bool AttrCursor::getBool()
|
|||
debug("using cached Boolean attribute '%s'", getAttrPathStr());
|
||||
return *b;
|
||||
} else
|
||||
throw TypeError("'%s' is not a Boolean", getAttrPathStr());
|
||||
root->state.debug_throw(TypeError("'%s' is not a Boolean", getAttrPathStr()));
|
||||
}
|
||||
}
|
||||
|
||||
auto & v = forceValue();
|
||||
|
||||
if (v.type() != nBool)
|
||||
throw TypeError("'%s' is not a Boolean", getAttrPathStr());
|
||||
root->state.debug_throw(TypeError("'%s' is not a Boolean", getAttrPathStr()));
|
||||
|
||||
return v.boolean;
|
||||
}
|
||||
|
@ -583,14 +586,14 @@ std::vector<Symbol> AttrCursor::getAttrs()
|
|||
debug("using cached attrset attribute '%s'", getAttrPathStr());
|
||||
return *attrs;
|
||||
} else
|
||||
throw TypeError("'%s' is not an attribute set", getAttrPathStr());
|
||||
root->state.debug_throw(TypeError("'%s' is not an attribute set", getAttrPathStr()));
|
||||
}
|
||||
}
|
||||
|
||||
auto & v = forceValue();
|
||||
|
||||
if (v.type() != nAttrs)
|
||||
throw TypeError("'%s' is not an attribute set", getAttrPathStr());
|
||||
root->state.debug_throw(TypeError("'%s' is not an attribute set", getAttrPathStr()));
|
||||
|
||||
std::vector<Symbol> attrs;
|
||||
for (auto & attr : *getValue().attrs)
|
||||
|
|
|
@ -783,13 +783,14 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string_view path, c
|
|||
if (hasPrefix(path, "nix/"))
|
||||
return concatStrings(corepkgsPrefix, path.substr(4));
|
||||
|
||||
throw ThrownError({
|
||||
debug_throw(ThrownError({
|
||||
.msg = hintfmt(evalSettings.pureEval
|
||||
? "cannot look up '<%s>' in pure evaluation mode (use '--impure' to override)"
|
||||
: "file '%s' was not found in the Nix search path (add it using $NIX_PATH or -I)",
|
||||
path),
|
||||
.errPos = pos
|
||||
});
|
||||
}));
|
||||
return Path(); // should never execute due to debug_throw above.
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2542,7 +2542,7 @@ static void prim_zipAttrsWith(EvalState & state, const Pos & pos, Value * * args
|
|||
attrsSeen[attr.name].first++;
|
||||
} catch (TypeError & e) {
|
||||
e.addTrace(pos, hintfmt("while invoking '%s'", "zipAttrsWith"));
|
||||
throw;
|
||||
state.debug_throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3127,7 +3127,7 @@ static void prim_concatMap(EvalState & state, const Pos & pos, Value * * args, V
|
|||
state.forceList(lists[n], lists[n].determinePos(args[0]->determinePos(pos)));
|
||||
} catch (TypeError &e) {
|
||||
e.addTrace(pos, hintfmt("while invoking '%s'", "concatMap"));
|
||||
throw;
|
||||
state.debug_throw(e);
|
||||
}
|
||||
len += lists[n].listSize();
|
||||
}
|
||||
|
|
|
@ -108,16 +108,16 @@ static void fetchTree(
|
|||
|
||||
if (auto aType = args[0]->attrs->get(state.sType)) {
|
||||
if (type)
|
||||
throw Error({
|
||||
state.debug_throw(EvalError({
|
||||
.msg = hintfmt("unexpected attribute 'type'"),
|
||||
.errPos = pos
|
||||
});
|
||||
}));
|
||||
type = state.forceStringNoCtx(*aType->value, *aType->pos);
|
||||
} else if (!type)
|
||||
throw Error({
|
||||
state.debug_throw(EvalError({
|
||||
.msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
|
||||
.errPos = pos
|
||||
});
|
||||
}));
|
||||
|
||||
attrs.emplace("type", type.value());
|
||||
|
||||
|
@ -138,16 +138,16 @@ static void fetchTree(
|
|||
else if (attr.value->type() == nInt)
|
||||
attrs.emplace(attr.name, uint64_t(attr.value->integer));
|
||||
else
|
||||
throw TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
|
||||
attr.name, showType(*attr.value));
|
||||
state.debug_throw(TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
|
||||
attr.name, showType(*attr.value)));
|
||||
}
|
||||
|
||||
if (!params.allowNameArgument)
|
||||
if (auto nameIter = attrs.find("name"); nameIter != attrs.end())
|
||||
throw Error({
|
||||
state.debug_throw(EvalError({
|
||||
.msg = hintfmt("attribute 'name' isn’t supported in call to 'fetchTree'"),
|
||||
.errPos = pos
|
||||
});
|
||||
}));
|
||||
|
||||
input = fetchers::Input::fromAttrs(std::move(attrs));
|
||||
} else {
|
||||
|
@ -167,7 +167,7 @@ static void fetchTree(
|
|||
input = lookupInRegistries(state.store, input).first;
|
||||
|
||||
if (evalSettings.pureEval && !input.isImmutable())
|
||||
throw Error("in pure evaluation mode, 'fetchTree' requires an immutable input, at %s", pos);
|
||||
state.debug_throw(EvalError("in pure evaluation mode, 'fetchTree' requires an immutable input, at %s", pos));
|
||||
|
||||
auto [tree, input2] = input.fetch(state.store);
|
||||
|
||||
|
@ -206,17 +206,17 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
|||
else if (n == "name")
|
||||
name = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||
else
|
||||
throw EvalError({
|
||||
state.debug_throw(EvalError({
|
||||
.msg = hintfmt("unsupported argument '%s' to '%s'", attr.name, who),
|
||||
.errPos = *attr.pos
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
if (!url)
|
||||
throw EvalError({
|
||||
state.debug_throw(EvalError({
|
||||
.msg = hintfmt("'url' argument required"),
|
||||
.errPos = pos
|
||||
});
|
||||
}));
|
||||
} else
|
||||
url = state.forceStringNoCtx(*args[0], pos);
|
||||
|
||||
|
@ -228,7 +228,7 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
|||
name = baseNameOf(*url);
|
||||
|
||||
if (evalSettings.pureEval && !expectedHash)
|
||||
throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who);
|
||||
state.debug_throw(EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who));
|
||||
|
||||
auto storePath =
|
||||
unpack
|
||||
|
@ -240,8 +240,8 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
|||
? state.store->queryPathInfo(storePath)->narHash
|
||||
: hashFile(htSHA256, state.store->toRealPath(storePath));
|
||||
if (hash != *expectedHash)
|
||||
throw Error((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
||||
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true));
|
||||
state.debug_throw(EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
||||
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true)));
|
||||
}
|
||||
|
||||
state.allowPath(storePath);
|
||||
|
|
|
@ -84,7 +84,8 @@ void printValueAsJSON(EvalState & state, bool strict,
|
|||
.msg = hintfmt("cannot convert %1% to JSON", showType(v)),
|
||||
.errPos = v.determinePos(pos)
|
||||
});
|
||||
throw e.addTrace(pos, hintfmt("message for the trace"));
|
||||
e.addTrace(pos, hintfmt("message for the trace"));
|
||||
state.debug_throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +99,7 @@ void printValueAsJSON(EvalState & state, bool strict,
|
|||
void ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
||||
JSONPlaceholder & out, PathSet & context) const
|
||||
{
|
||||
throw TypeError("cannot convert %1% to JSON", showType());
|
||||
state.debug_throw(TypeError("cannot convert %1% to JSON", showType()));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue