Skip to content
Open
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
5 changes: 5 additions & 0 deletions example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ if !ismissing(responce_1) && responce_1 == 42
PlutoTeachingTools.confetti()
end

# ╔═╡ 957ec770-ab5b-4b0b-a38d-46834d96fb68
expected_failure() do
error("This is an error message")
end

# ╔═╡ 7596325b-7a1b-4fad-bac3-ae6743e3f8dd
md"""# Robust Local Resources"""

Expand Down
1 change: 1 addition & 0 deletions src/PlutoTeachingTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export RobustLocalResource
include("other.jl")
export WidthOverDocs
export confetti
export expected_failure

include("footnotes.jl")
export FootnotesInlineNumbered
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/chinese.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Chinese) = md"$sym 类

# other.jl
PlutoTeachingTools.full_width_mode_str(lang::Chinese) = "全屏模式"
PlutoTeachingTools.expected_failure_str(lang::Chinese) = "预期失败"
PlutoTeachingTools.expected_failure_text_str(lang::Chinese) = "代码预期会失败,但实际上成功执行了。"
PlutoTeachingTools.expected_error_message_str(lang::Chinese) = "预期错误信息"

# present.jl
PlutoTeachingTools.present_str(lang::Chinese) = "演示"
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/english.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ end

# other.jl
PlutoTeachingTools.full_width_mode_str(lang::English) = "Full Width Mode"
PlutoTeachingTools.expected_failure_str(lang::English) = "Expected failure"
PlutoTeachingTools.expected_failure_text_str(lang::English) = "The code was expected to fail, but it evaluated successfully."
PlutoTeachingTools.expected_error_message_str(lang::English) = "Expected error message"

# present.jl
PlutoTeachingTools.present_str(lang::English) = "present"
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/french.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ end

# other.jl
PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:French} = "Mode Pleine Largeur"
PlutoTeachingTools.expected_failure_str(lang::Lang) where {Lang<:French} = "Échec attendu"
PlutoTeachingTools.expected_failure_text_str(lang::Lang) where {Lang<:French} = "Le code était censé échouer, mais il a été évalué avec succès."
PlutoTeachingTools.expected_error_message_str(lang::Lang) where {Lang<:French} = "Message d'erreur attendu"

# present.jl
PlutoTeachingTools.present_str(lang::Lang) where {Lang<:French} = "présentation"
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/german.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ end
function PlutoTeachingTools.full_width_mode_str(lang::German)
return "Modus \"Volle Breite\""
end
PlutoTeachingTools.expected_failure_str(lang::German) = "Erwarteter Fehler"
PlutoTeachingTools.expected_failure_text_str(lang::German) = "Der Code sollte fehlschlagen, wurde aber erfolgreich ausgeführt."
PlutoTeachingTools.expected_error_message_str(lang::German) = "Erwartete Fehlermeldung"

# present.jl
PlutoTeachingTools.present_str(lang::German) = "präsentieren"
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/i18n.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ end

# other.jl
full_width_mode_str(lang::AbstractLanguage) = @error "Please define a translation."
expected_failure_str(lang::AbstractLanguage) = @error "Please define a translation."
expected_failure_text_str(lang::AbstractLanguage) = @error "Please define a translation."
expected_error_message_str(lang::AbstractLanguage) = @error "Please define a translation."

# present.jl
present_str(lang::AbstractLanguage) = @error "Please define a translation."
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/russian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ end
function PlutoTeachingTools.full_width_mode_str(lang::Russian)
return "Режим полной ширины"
end
PlutoTeachingTools.expected_failure_str(lang::Russian) = "Ожидаемая ошибка"
PlutoTeachingTools.expected_failure_text_str(lang::Russian) = "Ожидалось, что код завершится с ошибкой, но он выполнился успешно."
PlutoTeachingTools.expected_error_message_str(lang::Russian) = "Ожидаемое сообщение об ошибке"

# present.jl
PlutoTeachingTools.present_str(lang::Russian) = "презентация"
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/spanish.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ end
function PlutoTeachingTools.full_width_mode_str(lang::Spanish)
return "Modo Pantalla Completa"
end
PlutoTeachingTools.expected_failure_str(lang::Spanish) = "Fallo esperado"
PlutoTeachingTools.expected_failure_text_str(lang::Spanish) = "Se esperaba que el código fallara, pero se ejecutó correctamente."
PlutoTeachingTools.expected_error_message_str(lang::Spanish) = "Mensaje de error esperado"

# present.jl
PlutoTeachingTools.present_str(lang::Spanish) = "presentación"
Expand Down
37 changes: 37 additions & 0 deletions src/other.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,40 @@ function confetti()
</script>
""")
end

"""
expected_failure(f)

Run the function `f`, and if it throws an error, displays just the error message similar
to how Pluto renders errors. If it does not throw an error, display a warning in a yellow box.

```julia
expected_failure() do
error("This is an error message")
end
```
"""
function expected_failure(f; lang::AbstractLanguage=default_language[])
try
f()
MD(Admonition("warning", expected_failure_str(lang), [
text_to_content(expected_failure_text_str(lang))
]))
catch e
str = sprint() do io
showerror(IOContext(io, :color=>true), e)
end
@htl """
<div>
<jlerror>
<div class="error-header">
<secret-h1>$(expected_error_message_str(lang))</secret-h1>
</div>
<header style='overflow: auto;'>
$(Main.PlutoRunner.embed_display(Text(str)))
</header>
</jlerror>
</div>
"""
end
end
Loading