Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
Expand Down
1 change: 1 addition & 0 deletions src/ExceptionUnwrapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ unwrap_exception(e) = e
# to fail. You can unwrap the exception to discover the root cause of the failure.
unwrap_exception(e::Base.TaskFailedException) = e.task.exception
unwrap_exception(e::Base.CapturedException) = e.ex
unwrap_exception(e::Base.CompositeException) = length(e) == 1 ? first(e) : e

has_wrapped_exception(::T, ::Type{T}) where T = true

Expand Down
30 changes: 30 additions & 0 deletions test/ExceptionUnwrapping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ if VERSION >= v"1.3.0-"
e = CapturedException(ErrorException("oh no"), backtrace())
@test unwrap_exception(e) == ErrorException("oh no")
end

@testset "CompositeException with single exception" begin
inner = ErrorException("inner")
e = CompositeException([inner])
@test is_wrapped_exception(e)
@test unwrap_exception(e) === inner
@test unwrap_exception_to_root(e) === inner
@test has_wrapped_exception(e, ErrorException)
@test has_wrapped_exception(e, CompositeException)
@test !has_wrapped_exception(e, ArgumentError)
@test unwrap_exception_until(e, ErrorException) === inner
end

@testset "CompositeException with multiple exceptions" begin
e = CompositeException([ErrorException("a"), ArgumentError("b")])
@test !is_wrapped_exception(e)
@test unwrap_exception(e) === e
end

@testset "CompositeException from @sync with single task" begin
try
@sync @async error("inner")
catch e
@test e isa CompositeException
@test is_wrapped_exception(e)
@test has_wrapped_exception(e, ErrorException)
@test unwrap_exception_to_root(e) isa ErrorException
@test (unwrap_exception_to_root(e)::ErrorException).msg === "inner"
end
end
end

struct MyWrappedException{T}
Expand Down
Loading