Skip to content

Commit a94945b

Browse files
authored
Consider redacting printing of Axis types
This PR reduces the very long stacktraces that can sometimes occur with ComponentArrays, by having by default a reducted form of `Base.show` for Axis types. Example: ``` ERROR: MethodError: no method matching h(::ComponentMatrix{Float64, Matrix{Float64}, Tuple{Axis{...}, FlatAxis}}) Closest candidates are: h() at REPL[14]:1 Stacktrace: [1] top-level scope @ REPL[15]:1 ``` now gives ``` ERROR: MethodError: no method matching h(::ComponentMatrix{Float64, Matrix{Float64}, Tuple{Axis{...}, FlatAxis}}) Closest candidates are: h() at REPL[2]:1 Stacktrace: [1] top-level scope @ REPL[3]:1 ``` instead of ``` ERROR: MethodError: no method matching h(::ComponentMatrix{Float64, Matrix{Float64}, Tuple{Axis{(first = 1, second = 2, third = 3, fourth = 4)}, FlatAxis}}) Closest candidates are: h() at REPL[2]:1 Stacktrace: [1] top-level scope @ REPL[3]:1 ```
1 parent cbb24ef commit a94945b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/show.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Show AbstractAxis types
1+
# Show AbstractAxis instances
22
Base.show(io::IO, ::MIME"text/plain", ::Axis{IdxMap}) where IdxMap = print(io, "Axis$IdxMap")
33
Base.show(io::IO, ::Axis{IdxMap}) where IdxMap = print(io, "Axis$IdxMap")
44

@@ -22,9 +22,21 @@ Base.show(io::IO, ::ViewAxis{Inds, IdxMap, <:Ax}) where {Inds, IdxMap, Ax} =
2222
Base.show(io::IO, ::ViewAxis{Inds, IdxMap, <:NullorFlatAxis}) where {Inds, IdxMap} =
2323
print(io, Inds)
2424

25+
# Show reducted Axis types to avoid excessive stacktraces
26+
Base.show(io::IO, ::Type{Axis{IdxMap}}) where {IdxMap} = print(io, "Axis{...}")
27+
Base.show(io::IO, ::Type{FlatAxis}) = print(io, "FlatAxis")
28+
Base.show(io::IO, ::Type{NullAxis}) = print(io, "NullAxis")
29+
function Base.show(io::IO, ::Type{PartitionedAxis{PartSz,IdxMap,Ax}}) where {PartSz,IdxMap,Ax}
30+
return print(io, "PartitionedAxis{$PartSz, {...}, $Ax}")
31+
end
32+
Base.show(io::IO, ::Type{ShapedAxis{Shape,IdxMap}}) where {Shape,IdxMap} = print(io, "ShapedAxis($Shape, {...})")
33+
Base.show(io::IO, ::Type{ViewAxis{Inds,IdxMap,Ax}}) where {Inds,IdxMap,Ax} = print(io, "ViewAxis{$Inds, {...}, $Ax)")
34+
2535
Base.show(io::IO, ci::ComponentIndex) = print(io, "ComponentIndex($(ci.idx), $(ci.ax))")
2636

2737

38+
39+
2840
# Show ComponentArrays
2941
_print_type_short(io, ca; color=:normal) = _print_type_short(io, typeof(ca); color=color)
3042
_print_type_short(io, T::Type; color=:normal) = printstyled(io, T; color=color)

0 commit comments

Comments
 (0)