Julia: Optional generators swallow errors

Created on 23 Jan 2018  Â·  1Comment  Â·  Source: JuliaLang/julia

With the optional generator syntax from #23168, there is currently no way of discovering errors that occur while executing the optional generator. In the case of a @generated function (ie. generated_only), the error will at least be noticed at run-time, but with optional generators we'll just ignore any error: https://github.com/JuliaLang/julia/blob/bca94e4bd5f491661249c0ba0d83f3abdbbbcb43/base/compiler/utilities.jl#L89-L96

Just to be clear:

julia> function foo()
           if @generated
               error("I am invisible")
           else
               42
           end
       end
foo (generic function with 1 method)

julia> foo()
42

whereas

julia> @generated function bar()
           error("I am not invisible")
       end
bar (generic function with 1 method)

julia> bar()
ERROR: I am not invisible
Stacktrace:
 [1] error at ./error.jl:33 [inlined]
 [2] #s2#3(::Any) at ./REPL[5]:2
 [3] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:466
 [4] top-level scope

I've long had a local change that prints the error along with a backtrace, since with CUDAnative we don't even get to see the error of a @generated function (because of allocs, calls to the runtime, etc). Now that there's a similar situation with regular code, I wonder if we need to do something more user friendly.

error handling

Most helpful comment

What it should probably do is turn in an Expr(:error), which gets thrown at runtime.

>All comments

What it should probably do is turn in an Expr(:error), which gets thrown at runtime.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  Â·  3Comments

i-apellaniz picture i-apellaniz  Â·  3Comments

omus picture omus  Â·  3Comments

manor picture manor  Â·  3Comments

yurivish picture yurivish  Â·  3Comments