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

Debugging: Line numbers and originating signal #118

Open
TsurHerman opened this issue Jan 26, 2017 · 11 comments
Open

Debugging: Line numbers and originating signal #118

TsurHerman opened this issue Jan 26, 2017 · 11 comments

Comments

@TsurHerman
Copy link
Contributor

I find it is very hard to track down error messages when something goes wrong (failed to push!)
My suggestion is to encode line numbers in the signal definition so the error message would look like:

Error: failed to push!
[from] signal defined in: (line number of originating signal)
[to] signal defined in :(line number of receiving signal)
error message: message

And display only the first occurrence of error instead of flooding the console with subsequent errors.

@shashi
Copy link
Member

shashi commented Jan 30, 2017

Great idea.

As far as I understand the @LINE macro talks about the line number where it is invoked. So there may not be an easy way to do this without additional macro-based API.

For example, it would be possible with something like:

@trackline x = Signal(0)
@trackline map(-, x) etc.

@JobJob
Copy link
Member

JobJob commented Jan 31, 2017

Unfortunately returning an expression with @__LINE__ in a macro won't give you the line where the macro was invoked:

macro linetest()
    :(@__LINE__)
end
@linetest(), @__LINE__

Gives (2,4)

See this issue: JuliaLang/julia#9577
A couple of PRs but no resolution as yet.

So, given that, not sure if a @trackline macro could help (I don't think you can rely on LineNumberNodes)?

One thing that could be done though is to add keyword arguments, something like:
map(-, x; line=@__LINE__, file=@__FILE__)
These could be added to each Reactive node and then you could access them on error. Bit ugly though.

I think possibly a better solution for now would be to add the ability to name nodes. I have this in this branch: https://github.com/JobJob/Reactive.jl/tree/named_signals
It seems to be working, but it might be terrible, haven't really looked at it in a while. Let me know what you think.

Usage like so:

#Pkg.clone("https://github.com/JobJob/Reactive.jl.git","named_signals")
using Reactive
s1 = Signal(1; name="sig1")
m1 = map(x->x==0?error():2/x, s1; name="map1")
push!(s1, 0)

You get the error:

Failed to push!
    0
to node
    sig1: Signal{Int64}(0, nactions=1)

error at node: map1: Signal{Float64}(2.0, nactions=0)
...

You can use name="map at $(@__FILE__):$(@__LINE__)" if you like.

@shashi
Copy link
Member

shashi commented Jan 31, 2017

@JobJob I think naming Signals is a good idea in order to improve debugging experience! Can you make a PR?

@JobJob
Copy link
Member

JobJob commented Jan 31, 2017

Ok but it prob needs a bit of review, from memory I was fairly slapdash about getting it up and running.

@TsurHerman
Copy link
Contributor Author

Just a comment , what generates errors are the actions not the signals .. so maybe it would be better to name actions.

@JobJob
Copy link
Member

JobJob commented Feb 1, 2017

Yep, you make a good point. As it turns out, each action is effectively associated with just one particular Signal/Node (the action's recipient), so reporting that node on error should be ok.

@timholy
Copy link
Member

timholy commented Feb 1, 2017

The annoyance of not being able to use @trackline might be circumvented by semantic replacement: parsing the test script (see JuliaParser) and replacing a @trackline Signal(0) expression with Signal(0, @__FILE__, @__LINE__) and then evaling it. Somewhat similar to tricks used in https://github.com/timholy/DebuggingUtilities.jl.

@shashi
Copy link
Member

shashi commented Feb 1, 2017

That's great!

@SimonDanisch
Copy link
Member

Another sketchy trick the macro could expand to:

s = Signal(..., lineinfo = ()-> nothing)

first(methods(s.lineinfo)).line
first(methods(s.lineinfo)).file

@c42f
Copy link

c42f commented Mar 18, 2017

I've got a PR in progress to solve this, if anyone feels like trying it out:
JuliaLang/julia#20895

@rand5
Copy link

rand5 commented Aug 7, 2017

Just to provide clarity, how should I interpret the following message when my code only has 149 lines of code:

Failed to push!
    989
to node
    910: "input-527" = 989 Int64 (active)

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

7 participants