nickel
nickel copied to clipboard
Extended error backtrace
Is your feature request related to a problem? Please describe. When an error occurs Nickel relies on internal heuristics to print out a backtrace that lead to an error. In some cases it doesn't get it right and there is no way to figure out where the value that led to an error originated from.
Describe the solution you'd like
I would propose adding an additional flag to nickel, similar to nix's --show-trace
which prints out an extended backtrace. Maybe you could have different levels of backtrace as well, for example filtering out internals like stdlib. I think we'd also want to set this through an environmental variable in case nickel was executed inside a script. Maybe a way to toggle this in the repl as well.
Describe alternatives you've considered Ideally this shouldn't be necessary and Nickel heuristics were good enough to always print out where the value originated from. I don't understand the internals enough to comment on how viable that is though.
Examples
Example 1:
nickel> let f = fun a => a + 1 in
let g = fun a => f a in
g ""
error: dynamic type error
┌─ repl-input-2:1:18
│
1 │ let f = fun a => a + 1 in
│ ^ this expression has type String, but Number was expected
│
= (+) expects its 1st argument to be a Number
Example 2:
let C = std.contract.from_predicate (fun x => std.is_number x) in
let f = fun a => (a | C) + 1 in
let g = fun a => f a in
g ""
error: contract broken by a value
┌─ /home/user/input.ncl:2:19
│
2 │ let f = fun a => (a | C) + 1 in
│ ^ - expected type
│ │
│ applied to this expression
│
┌─ <unknown> (generated by evaluation):1:1
│
1 │ ""
│ -- evaluated to this value