Skip to content

Commit

Permalink
Consistency with 1.11, lower bound 1.10, REPL to ext
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick committed Sep 24, 2024
1 parent 587b8f5 commit c1027b6
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 285 deletions.
11 changes: 5 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name = "AbbreviatedStackTraces"
uuid = "ac637c84-cc71-43bf-9c33-c1b4316be3d4"
authors = ["Nicholas Bauer <nicholasbauer@outlook.com>"]
version = "0.2.3"

[deps]
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
version = "0.3.0"

[weakdeps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[extensions]
DistributedExt = ["Distributed"]
AbbrvStackTracesDistributedExt = ["Distributed"]
AbbrvStackTracesREPLExt = ["REPL"]

[compat]
Distributed = "1"
REPL = "1"
julia = "1.9"
julia = "1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module DistributedExt
module AbbrvStackTracesDistributedExt

__precompile__(false)

Expand Down
42 changes: 30 additions & 12 deletions src/override-REPL.jl → ext/AbbrvStackTracesREPLExt.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
module AbbrvStackTracesREPLExt

__precompile__(false)

import REPL:
print_response

if VERSION v"1.11"
import REPL:
repl_display_error
end

import Base:
MainInclude

function repl_display_error(errio::IO, @nospecialize errval)
# this will be set to true if types in the stacktrace are truncated
limit_types_flag = Ref(false)
# this will be set to false if frames in the stacktrace are not hidden
hide_internal_frames_flag = Ref(true)

errio = IOContext(errio, :stacktrace_types_limited => limit_types_flag, :compacttrace => hide_internal_frames_flag)
Base.invokelatest(Base.display_error, errio, errval)
if limit_types_flag[] || hide_internal_frames_flag[]
limit_types_flag[] && print(errio, "Some type information was truncated. ")
hide_internal_frames_flag[] && print(errio, "Some frames were hidden. ")
print(errio, "Use `show(err)` to see complete trace.")
println(errio)
end
return nothing
end

function print_response(errio::IO, response, show_value::Bool, have_color::Bool, specialdisplay::Union{AbstractDisplay,Nothing}=nothing)
Base.sigatomic_begin()
val, iserr = response
Expand All @@ -14,12 +38,8 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
Base.sigatomic_end()
if iserr
val = Base.scrub_repl_backtrace(val)
if VERSION < v"1.10-alpha1"
Base.istrivialerror(val) || setglobal!(Main, :err, val)
else
Base.istrivialerror(val) || setglobal!(MainInclude, :err, val)
end
Base.invokelatest(Base.display_error, errio, val, true)
Base.istrivialerror(val) || setglobal!(MainInclude, :err, val)
Base.invokelatest(repl_display_error, errio, val)
else
if val !== nothing && show_value
try
Expand All @@ -41,12 +61,8 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
println(errio, "SYSTEM (REPL): showing an error caused an error")
try
excs = Base.scrub_repl_backtrace(current_exceptions())
if VERSION < v"1.10-alpha1"
setglobal!(Main, :err, excs)
else
setglobal!(MainInclude, :err, excs)
end
Base.invokelatest(Base.display_error, errio, excs)
setglobal!(MainInclude, :err, excs)
Base.invokelatest(repl_display_error, errio, excs)
catch e
# at this point, only print the name of the type as a Symbol to
# minimize the possibility of further errors.
Expand All @@ -63,3 +79,5 @@ function print_response(errio::IO, response, show_value::Bool, have_color::Bool,
Base.sigatomic_end()
nothing
end

end
12 changes: 6 additions & 6 deletions src/AbbreviatedStackTraces.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module AbbreviatedStackTraces

include("override-vscode.jl")
include("override-error.jl") # sets const `oldversion = true` if ExceptionStack wasn't defined by Base
include("override-client.jl")
include("override-errorshow.jl")
include("override-show.jl")
include("override-stacktraces.jl")
include("override-REPL.jl")

import Base:
printstyled,
RefValue,
StackFrame,
stacktrace_contract_userdir,
stacktrace_expand_basepaths,
Expand Down Expand Up @@ -210,13 +208,15 @@ function show_compact_backtrace(io::IO, trace::Vector; print_linebreaks::Bool)
end

# print if frames other than top-level were omitted
if num_frames - 1 > num_vis_frames
hide_internal_frames_flag = get(io, :compacttrace, nothing)
if num_frames - 1 > num_vis_frames
if lasti < num_frames - 1
println(io)
print_omitted_modules(lasti + 1, num_frames - 1)
end
println(io)
print(io, "Use `err` to retrieve the full stack trace.")
hide_internal_frames_flag isa RefValue{Bool} && (hide_internal_frames_flag[] = true)
else
hide_internal_frames_flag isa RefValue{Bool} && (hide_internal_frames_flag[] = false)
end
end
end
Expand Down
10 changes: 0 additions & 10 deletions src/override-client.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
__precompile__(false)

import Base:
display_error,
printstyled,
scrub_repl_backtrace,
show_exception_stack,
stacktrace

function scrub_repl_backtrace(bt)
Expand All @@ -19,10 +16,3 @@ function scrub_repl_backtrace(bt)
end
return bt
end

function display_error(io::IO, stack::ExceptionStack, compacttrace::Bool = false)
printstyled(io, "ERROR: "; bold=true, color=Base.error_color())
show_exception_stack(IOContext(io, :limit => true, :compacttrace => isinteractive() ? compacttrace : false), stack)
println(io)
end
display_error(stack::ExceptionStack, compacttrace = false) = display_error(stderr, stack, compacttrace)
36 changes: 0 additions & 36 deletions src/override-error.jl

This file was deleted.

24 changes: 12 additions & 12 deletions src/override-errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ __precompile__(false)
import Base:
BIG_STACKTRACE_SIZE,
contractuser,
ExceptionStack,
Filesystem,
fixup_stdlib_path,
invokelatest,
print_module_path_file,
printstyled,
print_stackframe,
process_backtrace,
RefValue,
show,
show_backtrace,
show_exception_stack,
Expand All @@ -28,10 +30,6 @@ function show_backtrace(io::IO, t::Vector)
empty!(io[:last_shown_line_infos])
end

# this will be set to true if types in the stacktrace are truncated
limitflag = Ref(false)
io = IOContext(io, :stacktrace_types_limited => limitflag)

# t is a pre-processed backtrace (ref #12856)
if t isa Vector{Any}
filtered = t
Expand All @@ -53,17 +51,17 @@ function show_backtrace(io::IO, t::Vector)
return
else
try invokelatest(update_stackframes_callback[], filtered) catch end

hide_internal_frames_flag = get(io, :compacttrace, nothing)
hide_internal_frames = hide_internal_frames_flag isa RefValue{Bool} ? hide_internal_frames_flag[] : false

# process_backtrace returns a Vector{Tuple{Frame, Int}}
if get(io, :compacttrace, false) || parse(Bool, get(ENV, "JULIA_STACKTRACE_ABBREVIATED", "false"))
if hide_internal_frames || parse(Bool, get(ENV, "JULIA_STACKTRACE_ABBREVIATED", "false"))
show_compact_backtrace(io, filtered; print_linebreaks = stacktrace_linebreaks())
else
show_full_backtrace(io, filtered; print_linebreaks = stacktrace_linebreaks())
end
end

if limitflag[]
print(io, "\nSome type information was truncated. Use `show(err)` to see complete types.")
end
return
end

Expand All @@ -85,14 +83,16 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
print(io, " ", lpad("[" * string(i) * "]", digit_align_width))
print(io, " ")

minimal = (get(io, :compacttrace, false) || parse(Bool, get(ENV, "JULIA_STACKTRACE_ABBREVIATED", "false"))) && parse(Bool, get(ENV, "JULIA_STACKTRACE_MINIMAL", "false"))
StackTraces.show_spec_linfo(IOContext(io, :backtrace=>true), frame, minimal)
hide_internal_frames_flag = get(io, :compacttrace, nothing)
hide_internal_frames = hide_internal_frames_flag isa RefValue{Bool} ? hide_internal_frames_flag[] : false
hide_internal_frames = (hide_internal_frames || parse(Bool, get(ENV, "JULIA_STACKTRACE_ABBREVIATED", "false"))) && parse(Bool, get(ENV, "JULIA_STACKTRACE_MINIMAL", "false"))
StackTraces.show_spec_linfo(IOContext(io, :backtrace=>true), frame, hide_internal_frames)
if n > 1
printstyled(io, " (repeats $n times)"; color=:light_black)
end

# @ Module path / file : line
if minimal
if hide_internal_frames
print_module_path_file(io, modul, file, line; modulecolor, digit_align_width = 1)
else
println(io)
Expand Down
101 changes: 0 additions & 101 deletions src/override-show.jl

This file was deleted.

Loading

0 comments on commit c1027b6

Please sign in to comment.