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

Warnings to Errors? #16

Open
sbromberger opened this issue Dec 4, 2015 · 5 comments
Open

Warnings to Errors? #16

sbromberger opened this issue Dec 4, 2015 · 5 comments

Comments

@sbromberger
Copy link

julia> @require Base.Test begin
       foobarbaz()
       end
WARNING: Error requiring Base.Test from Main:
UndefVarError: foobarbaz not defined
 in anonymous at /Users/bromberger1/.julia/v0.4/Requires/src/require.jl:60
 in err at /Users/bromberger1/.julia/v0.4/Requires/src/require.jl:47
 in anonymous at /Users/bromberger1/.julia/v0.4/Requires/src/require.jl:59
 in withpath at /Users/bromberger1/.julia/v0.4/Requires/src/require.jl:37
 in anonymous at /Users/bromberger1/.julia/v0.4/Requires/src/require.jl:58
 in listenmod at /Users/bromberger1/.julia/v0.4/Requires/src/require.jl:21

This is a bit dangerous (and causes tests to succeed when the functions that are being tested have errors). Is there a way to specify "rethrow errors"?

@MikeInnes
Copy link
Collaborator

The tricky part is making this consistent. If Foo requires Bar, which module throws an error depends on the order they are loaded, and to my mind it makes less sense for using Bar to throw an error because of a problem with Foo. Basically, any plan to change the current behaviour needs a solid plan to cover all bases.

@sbromberger
Copy link
Author

I'm not sure I understand - in the case above, where we're using @require as a conditional dependency loader, if there's an error in a function within the block it's not thrown. For testing, the error will never be caught since @require will throw a warning instead of an error. The above was a minimal test case, but let me show you how I'm using it:

in test/imports.jl

# if MatrixDepot is available, test somefn()
@require MatrixDepot begin
@test LightGraphs.somefn()
end

somefn() has an error it in, but this code will not cause a testing failure so it can go undetected unless someone's paying attention to warnings.

@MikeInnes
Copy link
Collaborator

In that case you should use if isdefined(Main, :MatrixDepot) ... or something similar – you want conditional evaluation, not delayed evaluation.

What @require is doing here is setting up some code if and when MatrixDepot is loaded. So the following sequence of events is possible:

# No error here since MatrixDepot is not loaded
@require MatrixDepot begin
  @test LightGraphs.somefn()
end

using MatrixDepot
# Require block executes, `somefun()` is not defined

If we were to throw an error here, it would indicate that using MatrixDepot has failed, when in fact the error comes from another package.

@sbromberger
Copy link
Author

In that case you should use if isdefined(Main, :MatrixDepot) ... or something similar – you want conditional evaluation, not delayed evaluation.

Unfortunately that won't work if the package you want uses macros... this is why Requires.jl is so cool :)

@MikeInnes
Copy link
Collaborator

Fair enough – in that case I think you probably want something bespoke ;) How about something like

if isdefined(Main, :MatrixDepot)
  eval(quote
    using MatrixDepot
    # ....
  end)
end

You could macroify that and it wouldn't be so bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants