From 21a58dd1a8ffff73633ab6d1f8c12a8e950c1b74 Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Mon, 3 Oct 2022 17:25:15 +0200 Subject: [PATCH] Loader hook, ExceptionalResponse constructor, migration guide update --- Project.toml | 2 +- docs/src/guides/Migrating_from_v4_to_v5.md | 12 +++++++++++- src/Exceptions.jl | 3 +++ src/Loader.jl | 8 ++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 53c00fd11..8b2050244 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Genie" uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e" authors = ["Adrian Salceanu "] -version = "5.6.2" +version = "5.7.0" [deps] ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" diff --git a/docs/src/guides/Migrating_from_v4_to_v5.md b/docs/src/guides/Migrating_from_v4_to_v5.md index c20c070cd..3c38e4bad 100644 --- a/docs/src/guides/Migrating_from_v4_to_v5.md +++ b/docs/src/guides/Migrating_from_v4_to_v5.md @@ -144,6 +144,16 @@ Genie v4 apps would automatically import `Genie` in `Main`, so that `Genie` woul The scripts responsible for starting the app in non-interactive/serving mode need to be updated by replacing the end of the command from `s "$@"` to `-s=true "$@"`. -### 19. Other +### 19. Update `config/initializers/logging.jl` + +Update the content of the `logging.jl` initializer to this: + +```julia +import Genie + +Genie.Logger.initialize_logging() +``` + +### 20. Other Genie 5 also changes or removes other APIs which can be generally be considered as internal. If you find other important breaking changes that have been missed, please open an issue on the Genie GitHub repository or just edit this file and submit a PR. diff --git a/src/Exceptions.jl b/src/Exceptions.jl index e2bc4d79d..1cdea5e71 100644 --- a/src/Exceptions.jl +++ b/src/Exceptions.jl @@ -24,6 +24,9 @@ isauthenticated() || throw(ExceptionalResponse(redirect(:show_login))) struct ExceptionalResponse <: Exception response::HTTP.Response end +function ExceptionalResponse(status, headers, body) + HTTP.Response(status, headers, body) |> ExceptionalResponse +end Base.show(io::IO, ex::ExceptionalResponse) = print(io, "ExceptionalResponseException: $(ex.response.status) - $(Dict(ex.response.headers))") diff --git a/src/Loader.jl b/src/Loader.jl index a2233bcef..f9d135b58 100644 --- a/src/Loader.jl +++ b/src/Loader.jl @@ -8,6 +8,7 @@ import REPL, REPL.Terminals import Revise import Genie +const post_load_hooks = Function[] ### PRIVATE ### @@ -234,6 +235,13 @@ function load(; context::Union{Module,Nothing} = nothing) :: Nothing Genie.Repl.replprint("$i ✅", t; prefix = "Loading ", clearline = 3, color = :green, sleep_time = 0.1) end + if ! isempty(post_load_hooks) + Genie.Repl.replprint("Running post load hooks ✅", t; clearline = 3, color = :green, sleep_time = 0.1) + for f in unique(post_load_hooks) + f |> Base.invokelatest + end + end + Genie.Repl.replprint("\nReady! \n", t; clearline = 1, color = :green, bold = :true) println()