Skip to content

Commit 9b33ef3

Browse files
committed
Revert "Merge pull request #6204 from layus/coerce-string"
This reverts commit a75b7ba, reversing changes made to 9af16c5.
1 parent 98f57f4 commit 9b33ef3

31 files changed

Lines changed: 859 additions & 982 deletions

doc/manual/src/release-notes/rl-2.13.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
* Instead of "antiquotation", the more common term [string interpolation](../language/string-interpolation.md) is now used consistently.
1919
Historical release notes were not changed.
2020

21-
* Error traces have been reworked to provide detailed explanations and more
22-
accurate error locations. A short excerpt of the trace is now shown by
23-
default when an error occurs.
24-
2521
* Allow explicitly selecting outputs in a store derivation installable, just like we can do with other sorts of installables.
2622
For example,
2723
```shell-session

src/libcmd/installables.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ ref<eval_cache::EvalCache> openEvalCache(
554554
auto vFlake = state.allocValue();
555555
flake::callFlake(state, *lockedFlake, *vFlake);
556556

557-
state.forceAttrs(*vFlake, noPos, "while parsing cached flake data");
557+
state.forceAttrs(*vFlake, noPos);
558558

559559
auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs"));
560560
assert(aOutputs);
@@ -618,7 +618,7 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths()
618618

619619
else if (v.type() == nString) {
620620
PathSet context;
621-
auto s = state->forceString(v, context, noPos, fmt("while evaluating the flake output attribute '%s'", attrPath));
621+
auto s = state->forceString(v, context, noPos);
622622
auto storePath = state->store->maybeParseStorePath(s);
623623
if (storePath && context.count(std::string(s))) {
624624
return {{

src/libcmd/repl.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ StringSet NixRepl::completePrefix(const std::string & prefix)
397397
Expr * e = parseString(expr);
398398
Value v;
399399
e->eval(*state, *env, v);
400-
state->forceAttrs(v, noPos, "nevermind, it is ignored anyway");
400+
state->forceAttrs(v, noPos);
401401

402402
for (auto & i : *v.attrs) {
403403
std::string_view name = state->symbols[i.name];
@@ -590,7 +590,7 @@ bool NixRepl::processLine(std::string line)
590590
const auto [path, line] = [&] () -> std::pair<Path, uint32_t> {
591591
if (v.type() == nPath || v.type() == nString) {
592592
PathSet context;
593-
auto path = state->coerceToPath(noPos, v, context, "while evaluating the filename to edit");
593+
auto path = state->coerceToPath(noPos, v, context);
594594
return {path, 0};
595595
} else if (v.isLambda()) {
596596
auto pos = state->positions[v.lambda.fun->pos];
@@ -839,7 +839,7 @@ void NixRepl::loadFiles()
839839

840840
void NixRepl::addAttrsToScope(Value & attrs)
841841
{
842-
state->forceAttrs(attrs, [&]() { return attrs.determinePos(noPos); }, "while evaluating an attribute set to be merged in the global scope");
842+
state->forceAttrs(attrs, [&]() { return attrs.determinePos(noPos); });
843843
if (displ + attrs.attrs->size() >= envSize)
844844
throw Error("environment full; cannot add more variables");
845845

@@ -944,7 +944,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
944944
Bindings::iterator i = v.attrs->find(state->sDrvPath);
945945
PathSet context;
946946
if (i != v.attrs->end())
947-
str << state->store->printStorePath(state->coerceToStorePath(i->pos, *i->value, context, "while evaluating the drvPath of a derivation"));
947+
str << state->store->printStorePath(state->coerceToStorePath(i->pos, *i->value, context));
948948
else
949949
str << "???";
950950
str << "»";

src/libexpr/attr-path.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ std::pair<std::string, uint32_t> findPackageFilename(EvalState & state, Value &
118118

119119
// FIXME: is it possible to extract the Pos object instead of doing this
120120
// toString + parsing?
121-
auto pos = state.forceString(*v2, noPos, "while evaluating the 'meta.position' attribute of a derivation");
121+
auto pos = state.forceString(*v2);
122122

123123
auto colon = pos.rfind(':');
124124
if (colon == std::string::npos)

src/libexpr/eval-cache.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Value & AttrCursor::getValue()
385385
if (!_value) {
386386
if (parent) {
387387
auto & vParent = parent->first->getValue();
388-
root->state.forceAttrs(vParent, noPos, "while searching for an attribute");
388+
root->state.forceAttrs(vParent, noPos);
389389
auto attr = vParent.attrs->get(parent->second);
390390
if (!attr)
391391
throw Error("attribute '%s' is unexpectedly missing", getAttrPathStr());
@@ -571,14 +571,14 @@ std::string AttrCursor::getString()
571571
debug("using cached string attribute '%s'", getAttrPathStr());
572572
return s->first;
573573
} else
574-
root->state.error("'%s' is not a string", getAttrPathStr()).debugThrow<TypeError>();
574+
root->state.debugThrowLastTrace(TypeError("'%s' is not a string", getAttrPathStr()));
575575
}
576576
}
577577

578578
auto & v = forceValue();
579579

580580
if (v.type() != nString && v.type() != nPath)
581-
root->state.error("'%s' is not a string but %s", getAttrPathStr()).debugThrow<TypeError>();
581+
root->state.debugThrowLastTrace(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
582582

583583
return v.type() == nString ? v.string.s : v.path;
584584
}
@@ -613,7 +613,7 @@ string_t AttrCursor::getStringWithContext()
613613
return *s;
614614
}
615615
} else
616-
root->state.error("'%s' is not a string", getAttrPathStr()).debugThrow<TypeError>();
616+
root->state.debugThrowLastTrace(TypeError("'%s' is not a string", getAttrPathStr()));
617617
}
618618
}
619619

@@ -624,7 +624,7 @@ string_t AttrCursor::getStringWithContext()
624624
else if (v.type() == nPath)
625625
return {v.path, {}};
626626
else
627-
root->state.error("'%s' is not a string but %s", getAttrPathStr()).debugThrow<TypeError>();
627+
root->state.debugThrowLastTrace(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
628628
}
629629

630630
bool AttrCursor::getBool()
@@ -637,14 +637,14 @@ bool AttrCursor::getBool()
637637
debug("using cached Boolean attribute '%s'", getAttrPathStr());
638638
return *b;
639639
} else
640-
root->state.error("'%s' is not a Boolean", getAttrPathStr()).debugThrow<TypeError>();
640+
root->state.debugThrowLastTrace(TypeError("'%s' is not a Boolean", getAttrPathStr()));
641641
}
642642
}
643643

644644
auto & v = forceValue();
645645

646646
if (v.type() != nBool)
647-
root->state.error("'%s' is not a Boolean", getAttrPathStr()).debugThrow<TypeError>();
647+
root->state.debugThrowLastTrace(TypeError("'%s' is not a Boolean", getAttrPathStr()));
648648

649649
return v.boolean;
650650
}
@@ -696,7 +696,7 @@ std::vector<std::string> AttrCursor::getListOfStrings()
696696
std::vector<std::string> res;
697697

698698
for (auto & elem : v.listItems())
699-
res.push_back(std::string(root->state.forceStringNoCtx(*elem, noPos, "while evaluating an attribute for caching")));
699+
res.push_back(std::string(root->state.forceStringNoCtx(*elem)));
700700

701701
if (root->db)
702702
cachedValue = {root->db->setListOfStrings(getKey(), res), res};
@@ -714,14 +714,14 @@ std::vector<Symbol> AttrCursor::getAttrs()
714714
debug("using cached attrset attribute '%s'", getAttrPathStr());
715715
return *attrs;
716716
} else
717-
root->state.error("'%s' is not an attribute set", getAttrPathStr()).debugThrow<TypeError>();
717+
root->state.debugThrowLastTrace(TypeError("'%s' is not an attribute set", getAttrPathStr()));
718718
}
719719
}
720720

721721
auto & v = forceValue();
722722

723723
if (v.type() != nAttrs)
724-
root->state.error("'%s' is not an attribute set", getAttrPathStr()).debugThrow<TypeError>();
724+
root->state.debugThrowLastTrace(TypeError("'%s' is not an attribute set", getAttrPathStr()));
725725

726726
std::vector<Symbol> attrs;
727727
for (auto & attr : *getValue().attrs)

src/libexpr/eval-inline.hh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,33 @@ void EvalState::forceValue(Value & v, Callable getPos)
103103
else if (v.isApp())
104104
callFunction(*v.app.left, *v.app.right, v, noPos);
105105
else if (v.isBlackhole())
106-
error("infinite recursion encountered").atPos(getPos()).template debugThrow<EvalError>();
106+
throwEvalError(getPos(), "infinite recursion encountered");
107107
}
108108

109109

110110
[[gnu::always_inline]]
111-
inline void EvalState::forceAttrs(Value & v, const PosIdx pos, std::string_view errorCtx)
111+
inline void EvalState::forceAttrs(Value & v, const PosIdx pos)
112112
{
113-
forceAttrs(v, [&]() { return pos; }, errorCtx);
113+
forceAttrs(v, [&]() { return pos; });
114114
}
115115

116116

117117
template <typename Callable>
118118
[[gnu::always_inline]]
119-
inline void EvalState::forceAttrs(Value & v, Callable getPos, std::string_view errorCtx)
119+
inline void EvalState::forceAttrs(Value & v, Callable getPos)
120120
{
121-
forceValue(v, noPos);
122-
if (v.type() != nAttrs) {
123-
PosIdx pos = getPos();
124-
error("value is %1% while a set was expected", showType(v)).withTrace(pos, errorCtx).debugThrow<TypeError>();
125-
}
121+
forceValue(v, getPos);
122+
if (v.type() != nAttrs)
123+
throwTypeError(getPos(), "value is %1% while a set was expected", v);
126124
}
127125

128126

129127
[[gnu::always_inline]]
130-
inline void EvalState::forceList(Value & v, const PosIdx pos, std::string_view errorCtx)
128+
inline void EvalState::forceList(Value & v, const PosIdx pos)
131129
{
132-
forceValue(v, noPos);
133-
if (!v.isList()) {
134-
error("value is %1% while a list was expected", showType(v)).withTrace(pos, errorCtx).debugThrow<TypeError>();
135-
}
130+
forceValue(v, pos);
131+
if (!v.isList())
132+
throwTypeError(pos, "value is %1% while a list was expected", v);
136133
}
137134

138135

0 commit comments

Comments
 (0)