Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional generators swallow errors #25707

Open
maleadt opened this issue Jan 23, 2018 · 1 comment · May be fixed by #31756
Open

Optional generators swallow errors #25707

maleadt opened this issue Jan 23, 2018 · 1 comment · May be fixed by #31756
Labels
error handling Handling of exceptions by Julia or the user

Comments

@maleadt
Copy link
Member

maleadt commented Jan 23, 2018

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:

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.

@maleadt maleadt added the error handling Handling of exceptions by Julia or the user label Jan 23, 2018
@Keno
Copy link
Member

Keno commented Jan 23, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants