Skip to content

Commit

Permalink
Consider redacting printing of Axis types
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
nrontsis committed Oct 24, 2022
1 parent cbb24ef commit a94945b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/show.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Show AbstractAxis types
# Show AbstractAxis instances
Base.show(io::IO, ::MIME"text/plain", ::Axis{IdxMap}) where IdxMap = print(io, "Axis$IdxMap")
Base.show(io::IO, ::Axis{IdxMap}) where IdxMap = print(io, "Axis$IdxMap")

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

# Show reducted Axis types to avoid excessive stacktraces
Base.show(io::IO, ::Type{Axis{IdxMap}}) where {IdxMap} = print(io, "Axis{...}")
Base.show(io::IO, ::Type{FlatAxis}) = print(io, "FlatAxis")
Base.show(io::IO, ::Type{NullAxis}) = print(io, "NullAxis")
function Base.show(io::IO, ::Type{PartitionedAxis{PartSz,IdxMap,Ax}}) where {PartSz,IdxMap,Ax}
return print(io, "PartitionedAxis{$PartSz, {...}, $Ax}")
end
Base.show(io::IO, ::Type{ShapedAxis{Shape,IdxMap}}) where {Shape,IdxMap} = print(io, "ShapedAxis($Shape, {...})")
Base.show(io::IO, ::Type{ViewAxis{Inds,IdxMap,Ax}}) where {Inds,IdxMap,Ax} = print(io, "ViewAxis{$Inds, {...}, $Ax)")

Base.show(io::IO, ci::ComponentIndex) = print(io, "ComponentIndex($(ci.idx), $(ci.ax))")




# Show ComponentArrays
_print_type_short(io, ca; color=:normal) = _print_type_short(io, typeof(ca); color=color)
_print_type_short(io, T::Type; color=:normal) = printstyled(io, T; color=color)
Expand Down

0 comments on commit a94945b

Please sign in to comment.