From 8d2be51d19830754db260e91521e58a947719574 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 9 Jun 2021 16:28:41 +0200 Subject: [PATCH] Cache the evaluation errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Doesn’t seem to make much of a difference on `nix search`, but we’ll need it at some point --- src/libexpr/eval.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index cc562328a..48752a925 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1261,7 +1261,12 @@ bool EvalState::getAttrField(Value & attrs, const std::vector & selector } vAttrs = j->value; pos2 = j->pos; - forceValue(*vAttrs, pos2 != NULL ? *pos2 : pos ); + try { + forceValue(*vAttrs, pos2 != NULL ? *pos2 : pos ); + } catch (EvalError & e) { + resultingCursor.addFailedChild(name, e); + throw; + } if (cacheResult.returnCode == ValueCache::CacheMiss) { resultingCursor = resultingCursor.addChild(name, *vAttrs); vAttrs->setEvalCache(resultingCursor); @@ -1984,6 +1989,13 @@ ValueCache ValueCache::addChild(const Symbol& name, Value& value) return ret; } + +ValueCache ValueCache::addFailedChild(const Symbol& name, const Error & error) +{ + if (!rawCache) return ValueCache::empty; + return ValueCache(rawCache->addChild(name, tree_cache::failed_t{ .error = error.msg() })); +} + void ValueCache::addAttrSetChilds(Bindings & children) { if (!rawCache) return;