zed icon indicating copy to clipboard operation
zed copied to clipboard

record errors derefenceable?

Open mccanne opened this issue 4 years ago • 2 comments

Should operators on errors work the same was as unions, where we automatically access the "under()" value. While this could cause confusing behavior, it also has some nice properties... e.g., creating timestamped errors where ts is the pool key...

switch (
  ...
  default => yield error({ts:now(), ...})
)

If the result error record allowed the ts field to be derefenced, then this would just work as a pool value alongside other values sorted by ts.

Right now you get a missing error when you do this...

echo 'error({x:1})' | zq "yield {x}" -
{x:error("missing")}

That said, we shouldn't magically make errors into non-errors inside expressions, so maybe we just let this record deref case be the important expcetion?

mccanne avatar Feb 06 '22 18:02 mccanne

@mccanne just bumped into what looks like a variation on this one. Repro is with Zed commit b6d853f.

In his own words:

$ zq -version
Version: v1.17.0-44-gb6d853fe

$ echo '{a:error({b:2})}' | zq 'yield a' -
error({b:2})

$ echo '{a:error({b:2})}' | zq 'yield a.b' -
error("missing")

The yield of a.b should give 2.

philrz avatar Sep 03 '24 17:09 philrz

We had another group chat about this one. There's consensus that the current behavior is actually ok, since when it's an error, if the underlying value was transparently returned, the user might miss out on seeing there ever was an error, and that seems bad. At the same time, the user would still surely want a way to get at the underlying values when they need to, such as if they're intentionally going in to find and fix errors. Therefore our thinking is now that there should be some kind of explicit "de-error" operator/function. Naming is TBD.

This was estimated as something we might want to have working for some demos in the October, 2024 timeframe.

philrz avatar Sep 05 '24 18:09 philrz