Skip to content

Commit bd214f3

Browse files
authored
Merge pull request #45 from Klafyvel/feat-send-module-info
feat(protocol): Send module information when smuggling errors.
2 parents 7f24d17 + 9a45510 commit bd214f3

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "REPLSmuggler"
22
uuid = "ad7bff83-59f0-4382-9fe5-c2ac8aa77434"
33
authors = ["Hugo Levy-Falk <hugo@klafyvel.me> and contributors"]
4-
version = "0.5.1"
4+
version = "0.6.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/Protocols.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ If an error occured, then the error field is a three-elements array structured a
6565
- `exception::String`: Name of the exception, *e.g.* `"ValueError"`,
6666
- `exception_text::String`: Text, *e.g.* `"This value cannot be < 0."`,
6767
- `stacktrace::Vector{Tuple{String, UInt32, String}}`: The stacktrace, with each
68-
row being `(file, line, function)`.
68+
row being `(file, line, function, module)`. Module can be `nil`.
6969
7070
## Notifications by the server.
7171
@@ -110,7 +110,7 @@ using ..REPLSmuggler: stringify_error
110110
"Name of the protocol implementation."
111111
const PROTOCOL_MAGIC = "REPLSmuggler"
112112
"Protocol version."
113-
const PROTOCOL_VERSION = v"0.4"
113+
const PROTOCOL_VERSION = v"0.5"
114114

115115
"Supported image MIME types."
116116
const IMAGE_MIME = [
@@ -283,7 +283,7 @@ end
283283
Error(msgid, error, stackframe)
284284
"""
285285
function Error(msgid, error::T, stackframe) where {T}
286-
frames = [(frame.file, frame.line, frame.func) for frame in stackframe]
286+
frames = [(frame.file, frame.line, frame.func, isnothing(frame.parentmodule) ? nothing : string(frame.parentmodule)) for frame in stackframe]
287287
ErrorResponse(
288288
msgid,
289289
string(T), stringify_error(error), frames,

src/eval.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ function stripblock(s)
6161
return String(take!(io))
6262
end
6363

64+
function scrub_repl_backtrace(backtrace)
65+
scrubbed_by_base = Base.scrub_repl_backtrace(backtrace)
66+
scrubbed = []
67+
for sf in scrubbed_by_base
68+
parentmodule = Base.parentmodule(sf)
69+
if parentmodule == Base
70+
# Taken from Atom.jl: src/utils.jl
71+
path = normpath(Sys.BINDIR::String, Base.DATAROOTDIR, "julia", "base", string(sf.file))
72+
else
73+
path = sf.file
74+
end
75+
push!(scrubbed, (file = path, line = sf.line, func = string(sf.func), parentmodule = parentmodule))
76+
end
77+
return scrubbed
78+
end
79+
6480
"""
6581
evaluate_entry(session, msgid, file, line, value, repl=Base.active_repl))
6682
@@ -108,7 +124,8 @@ function evaluate_entry(session, msgid, file, line, value, repl = Base.active_re
108124
REPL.LineEdit.refresh_line(s)
109125

110126
if !isnothing(error)
111-
put!(session.responsechannel, Protocols.Error(msgid, error.exception, error.stack))
127+
stack = scrub_repl_backtrace(error.stack)
128+
put!(session.responsechannel, Protocols.Error(msgid, error.exception, stack))
112129
elseif !hide_output && !isnothing(first(repl_response))
113130
index_mime = session.sessionparams["enableimages"] ? findfirst([Base.invokelatest(showable, mime, first(repl_response)) for mime in Protocols.IMAGE_MIME]) : nothing
114131
@debug "Show time." index_mime first(repl_response)

test/msgpackserializer.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ using MsgPack
2626

2727
msg = Protocols.Error(
2828
1, ErrorException("Foo"), [
29-
(file = "foo.jl", line = 1, func = "foo()"),
30-
(file = "bar.jl", line = 2, func = "bar()"),
29+
(file = "foo.jl", line = 1, func = "foo()", parentmodule = "Main"),
30+
(file = "bar.jl", line = 2, func = "bar()", parentmodule = "Main"),
3131
],
3232
)
33-
expected_array = [Protocols.RESPONSE, 0x01, ["ErrorException", "ErrorException: Foo", [("foo.jl", 1, "foo()"), ("bar.jl", 2, "bar()")]], nothing]
33+
expected_array = [Protocols.RESPONSE, 0x01, ["ErrorException", "ErrorException: Foo", [("foo.jl", 1, "foo()", "Main"), ("bar.jl", 2, "bar()", "Main")]], nothing]
3434
@testset "Error" test_msg(msg, expected_array)
3535

3636
msg = Protocols.Result(1, 1, "foo")

test/protocol.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ using REPLSmuggler.Protocols
4343
Protocols.serialize(
4444
protocol, Protocols.Error(
4545
1, ErrorException("Foo"), [
46-
(file = "foo.jl", line = 1, func = "foo()"),
47-
(file = "bar.jl", line = 2, func = "bar()"),
46+
(file = "foo.jl", line = 1, func = "foo()", parentmodule = "Main"),
47+
(file = "bar.jl", line = 2, func = "bar()", parentmodule = "Main"),
4848
],
4949
),
5050
)
@@ -57,8 +57,8 @@ using REPLSmuggler.Protocols
5757
(
5858
"ErrorException", "ErrorException: Foo",
5959
[
60-
("foo.jl", 1, "foo()"),
61-
("bar.jl", 2, "bar()"),
60+
("foo.jl", 1, "foo()", "Main"),
61+
("bar.jl", 2, "bar()", "Main"),
6262
],
6363
),
6464
nothing,

0 commit comments

Comments
 (0)