-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
error handlingHandling of exceptions by Julia or the userHandling of exceptions by Julia or the user
Description
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:
julia/base/compiler/utilities.jl
Lines 89 to 96 in bca94e4
function get_staged(li::MethodInstance) | |
try | |
# user code might throw errors – ignore them | |
return ccall(:jl_code_for_staged, Any, (Any,), li)::CodeInfo | |
catch | |
return nothing | |
end | |
end |
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.
Metadata
Metadata
Assignees
Labels
error handlingHandling of exceptions by Julia or the userHandling of exceptions by Julia or the user