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

Error handling for entr when watching multiple files #481

Closed
ffevotte opened this issue May 16, 2020 · 1 comment
Closed

Error handling for entr when watching multiple files #481

ffevotte opened this issue May 16, 2020 · 1 comment

Comments

@ffevotte
Copy link
Collaborator

When watching multiple files with entr, and the user-provided function throws an error, entr does not immediately exit as I think it is intended to.

Steps to reproduce:

julia> import Revise
julia> import Dates

# Create two empty files
julia> open((f)->nothing, "/tmp/file1", "w")
julia> open((f)->nothing, "/tmp/file2", "w")

#... and watch them
julia> Revise.entr(["/tmp/file1", "/tmp/file2"]; postpone=true) do
           println("Something changed: ", Dates.now())
           error("KO")
       end

# Touch file1 from outside julia
# -> the user-provided function runs
Something changed: 2020-05-16T13:13:37.046
# -> the error has been thrown, but nothing seems to happen yet
# -> entr does not return

# Touch file1 again
# -> nothing happens; the user-provided function is not called

# Later touch file2
Something changed: 2020-05-16T13:14:00.926
# -> now the errors are shown and `entr` exits
ERROR: TaskFailedException:
KO
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] (::var"#9#10")() at ./REPL[5]:3
 [3] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [4] invokelatest at ./essentials.jl:711 [inlined]
 [5] macro expansion at /home/francois/.julia/packages/Revise/AMRie/src/Revise.jl:828 [inlined]
 [6] (::Revise.var"#81#82"{Float64,var"#9#10",typeof(FileWatching.watch_file),String})() at ./task.jl:358

...and 1 more exception(s).

I think this happens because one @async task is spawned for each watched file, and the try...catch block handling exception surrounds an @sync block synchronizing all these tasks. So that when an error is thrown in one of the @async tasks, nothing happens until all other tasks terminate one way or another.

I'm working on a (tentative) fix, and should be able to propose a PR in the coming hours...

ffevotte added a commit to ffevotte/Revise.jl that referenced this issue May 16, 2020
This stops all tasks watching individual files/directories when one of them
throws an error.

Fixes: timholygh-481
ffevotte added a commit to ffevotte/Revise.jl that referenced this issue May 16, 2020
This stops all tasks watching individual files/directories when one of them
throws an error.

Fixes: timholygh-481
@ffevotte
Copy link
Collaborator Author

Closed by #488

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

1 participant