Skip to content

Commit

Permalink
Rename TypstError to TypstCommandError
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobjpeters committed Nov 7, 2024
1 parent 15577c9 commit 0b302bb
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 57 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# News

## v0.5.0

- `TypstError` renamed to `TypstCommandError`
6 changes: 3 additions & 3 deletions docs/source/references/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Markdown.parse("This reference documents " * lowercasefirst(split(string(@doc Ty

```@docs
TypstCommand
TypstError
TypstCommandError
@typst_cmd
julia_mono
preamble
Expand Down Expand Up @@ -38,7 +38,7 @@ run
setcpuaffinity
setenv
show(::IO, ::MIME"text/plain", ::TypstCommand)
show(::IO, ::MIME"text/plain", ::TypstError)
show(::IO, ::MIME"text/plain", ::TypstCommandError)
show(::IO, ::Union{MIME"application/pdf", MIME"image/png", MIME"image/svg+xml"}, ::Union{Typst, TypstString, TypstText})
showerror(::IO, ::TypstError)
showerror(::IO, ::TypstCommandError)
```
2 changes: 1 addition & 1 deletion src/Commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using Artifacts: @artifact_str
using Preferences: @load_preference, @set_preferences!

include("typst_commands.jl")
include("typst_errors.jl")
include("typst_command_errors.jl")
include("preamble.jl")

# Internals
Expand Down
4 changes: 2 additions & 2 deletions src/Typstry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ using .Strings: ContextError, Mode, Typst, TypstString, TypstText, @typst_str, c
export ContextError, Mode, Typst, TypstString, TypstText, @typst_str, code, markup, math, context, show_typst

include("Commands.jl")
using .Commands: TypstCommand, TypstError, @typst_cmd, julia_mono, preamble, render, set_preamble, typst
export TypstCommand, TypstError, @typst_cmd, julia_mono, preamble, render, set_preamble, typst
using .Commands: TypstCommand, TypstCommandError, @typst_cmd, julia_mono, preamble, render, set_preamble, typst
export TypstCommand, TypstCommandError, @typst_cmd, julia_mono, preamble, render, set_preamble, typst

compile_workload(Strings.examples)

Expand Down
47 changes: 47 additions & 0 deletions src/typst_command_errors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

"""
TypstCommandError <: Exception
TypstCommandError(::TypstCommand)
An `Exception` indicating a failure to [`run`](@ref) a [`TypstCommand`](@ref).
# Examples
```jldoctest
julia> TypstCommandError(typst``)
TypstCommandError(typst``)
```
"""
struct TypstCommandError <: Exception
command::TypstCommand
end

"""
show(::IO, ::MIME"text/plain", ::TypstCommandError)
# Examples
```jldoctest
julia> show(stdout, "text/plain", TypstCommandError(typst``))
TypstCommandError(typst``)
```
"""
function show(io::IO, m::MIME"text/plain", te::TypstCommandError)
print(io, TypstCommandError, "(")
show(io, m, te.command)
print(io, ")")
end

"""
showerror(::IO, ::TypstCommandError)
Print a [`TypstCommandError`](@ref) when failing to [`run`](@ref) a [`TypstCommand`](@ref).
# Examples
```jldoctest
julia> showerror(stdout, TypstCommandError(typst``))
TypstCommandError: failed to `run` a `TypstCommand(String[])`
```
"""
showerror(io::IO, te::TypstCommandError) = print(io,
"TypstCommandError: failed to `run` a `", TypstCommand, "(", te.command.parameters, ")`")
7 changes: 4 additions & 3 deletions src/typst_commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ hash(tc::TypstCommand, h::UInt) =
ignorestatus(::TypstCommand)
Return a [`TypstCommand`](@ref) that does not throw a
[`TypstError`](@ref) if the Typst compiler throws an error.
[`TypstCommandError`](@ref) if the Typst compiler throws an error.
Errors thrown by the Typst compiler are printed to `stderr` regardless.
Expand Down Expand Up @@ -229,11 +229,12 @@ See also [`TypstCommand`](@ref).
!!! info
Errors thrown by the Typst compiler will be printed to `stderr`.
Then, a Julia [`TypstError`](@ref) will be thrown unless the [`ignorestatus`](@ref) flag is set.
Then, a Julia [`TypstCommandError`](@ref) will be
thrown unless the [`ignorestatus`](@ref) flag is set.
"""
function run(tc::TypstCommand, args...; kwargs...)
process = run(ignorestatus(Cmd(`$(tc.compiler) $(tc.parameters)`)), args...; kwargs...)
tc.ignore_status || success(process) || throw(TypstError(tc))
tc.ignore_status || success(process) || throw(TypstCommandError(tc))
process
end

Expand Down
47 changes: 0 additions & 47 deletions src/typst_errors.jl

This file was deleted.

2 changes: 1 addition & 1 deletion test/interface/TestCommands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end

@testset "`run`" begin
# TODO: write more tests
@test_throws TypstError redirect_stderr(() -> run(tc_error), devnull)
@test_throws TypstCommandError redirect_stderr(() -> run(tc_error), devnull)
@test_warn "error" try run(tc_error) catch end
end

Expand Down

0 comments on commit 0b302bb

Please sign in to comment.