lix/src/libexpr
eldritch horrors 08252967a8 libexpr: Support structured error classes
While preparing PRs like #9753, I've had to change error messages in
dozens of code paths. It would be nice if instead of

    EvalError("expected 'boolean' but found '%1%'", showType(v))

we could write

    TypeError(v, "boolean")

or similar. Then, changing the error message could be a mechanical
refactor with the compiler pointing out places the constructor needs to
be changed, rather than the error-prone process of grepping through the
codebase. Structured errors would also help prevent the "same" error
from having multiple slightly different messages, and could be a first
step towards error codes / an error index.

This PR reworks the exception infrastructure in `libexpr` to
support exception types with different constructor signatures than
`BaseError`. Actually refactoring the exceptions to use structured data
will come in a future PR (this one is big enough already, as it has to
touch every exception in `libexpr`).

The core design is in `eval-error.hh`. Generally, errors like this:

    state.error("'%s' is not a string", getAttrPathStr())
      .debugThrow<TypeError>()

are transformed like this:

    state.error<TypeError>("'%s' is not a string", getAttrPathStr())
      .debugThrow()

The type annotation has moved from `ErrorBuilder::debugThrow` to
`EvalState::error`.

(cherry picked from commit c6a89c1a1659b31694c0fbcd21d78a6dd521c732)
Change-Id: Iced91ba4e00ca9e801518071fb43798936cbd05a
2024-03-09 04:47:05 -07:00
..
flake libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
primops libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
value Fixing #7479 2023-08-18 11:44:00 -04:00
attr-path.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
attr-path.hh Merge remote-tracking branch 'upstream/master' into source-path 2023-04-17 11:41:50 +02:00
attr-set.cc Don't pass Symbol by reference 2022-04-26 13:25:17 +02:00
attr-set.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
eval-cache.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
eval-cache.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
eval-error.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
eval-error.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
eval-inline.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
eval-settings.cc Merge pull request #4093 from matthewbauer/eval-system 2024-03-04 07:21:01 +01:00
eval-settings.hh Merge pull request #9617 from 9999years/stack-overflow-segfault 2024-03-04 07:35:20 +01:00
eval.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
eval.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
fetchurl.nix fetchurl.nix: change other use of __impure 2022-09-16 01:54:24 -07:00
function-trace.cc
function-trace.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
gc-small-vector.hh Merge pull request #9430 from hercules-ci/remove-vlas 2024-03-04 07:11:25 +01:00
get-drvs.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
get-drvs.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
imported-drv-to-derivation.nix
json-to-value.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
json-to-value.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
lexer.l libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
local.mk Merge pull request #9465 from obsidiansystems/build-dir 2024-03-04 07:11:25 +01:00
nix-expr.pc.in Fix building with GCC 9 2023-02-10 18:38:57 +01:00
nixexpr.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
nixexpr.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
parser-state.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
parser.y libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
paths.cc Merge pull request #9172 from tfc/bad-moves 2024-03-04 04:41:52 +01:00
pos-idx.hh Move PodIdx to pos-idx.hh and PosTable to pos-table.hh 2024-03-09 04:47:05 -07:00
pos-table.hh Move PodIdx to pos-idx.hh and PosTable to pos-table.hh 2024-03-09 04:47:05 -07:00
primops.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
primops.hh Merge pull request #7348 from thufschmitt/dont-use-vlas 2024-03-04 05:51:23 +01:00
print-ambiguous.cc Merge pull request #9753 from 9999years/print-value-on-type-error 2024-03-09 00:05:41 -07:00
print-ambiguous.hh Unify and refactor value printing 2024-03-09 03:50:06 +01:00
print-options.hh Merge pull request #9754 from 9999years/print-value-when-coercion-fails 2024-03-09 00:05:41 -07:00
print.cc Merge pull request #9928 from 9999years/error-messages-in-nix-repl 2024-03-09 03:37:35 -07:00
print.hh Merge pull request #9929 from 9999years/dont-print-values-in-magenta 2024-03-09 03:37:35 -07:00
search-path.cc src/libexpr/search-path.cc: avoid out-of-bounds read on string_view 2023-08-14 22:07:37 +01:00
search-path.hh Clean up SearchPath 2023-07-09 23:22:22 -04:00
symbol-table.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
value-to-json.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
value-to-json.hh Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
value-to-xml.cc Merge remote-tracking branch 'origin/master' into source-path 2023-04-24 13:20:36 +02:00
value-to-xml.hh Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
value.hh libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00