From c56797c17eafd25d1ad87cb3597c2bb4d1aae59b Mon Sep 17 00:00:00 2001 From: John Coene Date: Sat, 6 Jan 2024 13:50:18 +0100 Subject: [PATCH] fix: error handling on viewer --- DESCRIPTION | 2 +- R/utils.R | 8 ++++- makefile | 3 ++ man/Ambiorix.Rd | 24 ++++++------- man/Router.Rd | 24 ++++++------- tests/testthat/_snaps/app.md | 8 +++++ tests/testthat/_snaps/cookie.md | 14 ++++++++ tests/testthat/_snaps/forward.md | 7 ++++ tests/testthat/_snaps/log.md | 32 +++++++++++++++++ tests/testthat/_snaps/request.md | 52 +++++++++++++++++++++++++++ tests/testthat/_snaps/response.md | 57 ++++++++++++++++++++++++++++++ tests/testthat/_snaps/router.md | 8 +++++ tests/testthat/_snaps/websocket.md | 16 +++++++++ 13 files changed, 229 insertions(+), 26 deletions(-) create mode 100644 tests/testthat/_snaps/app.md create mode 100644 tests/testthat/_snaps/cookie.md create mode 100644 tests/testthat/_snaps/forward.md create mode 100644 tests/testthat/_snaps/log.md create mode 100644 tests/testthat/_snaps/request.md create mode 100644 tests/testthat/_snaps/response.md create mode 100644 tests/testthat/_snaps/router.md create mode 100644 tests/testthat/_snaps/websocket.md diff --git a/DESCRIPTION b/DESCRIPTION index c398b83..7c68471 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ License: GPL-3 Encoding: UTF-8 LazyData: false Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 Depends: R (>= 4.1.0) Imports: fs, diff --git a/R/utils.R b/R/utils.R index 554e03f..82eba0b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -12,7 +12,13 @@ browse_ambiorix <- function(open, url){ viewer <- getOption("viewer", browseURL) - viewer(url) + x <- tryCatch( + viewer(url), + error = function(e) e + ) + + if(inerits(x, "error")) + cat("Unable to open browser, please open manually.\n") invisible() } diff --git a/makefile b/makefile index 2fd53eb..9c767a4 100644 --- a/makefile +++ b/makefile @@ -9,3 +9,6 @@ document: test: Rscript -e "devtools::test()" + +dev: + Rscript test.R diff --git a/man/Ambiorix.Rd b/man/Ambiorix.Rd index e6276f8..67acdaa 100644 --- a/man/Ambiorix.Rd +++ b/man/Ambiorix.Rd @@ -128,18 +128,18 @@ if(interactive()) \if{html}{\out{
Inherited methods
}} diff --git a/man/Router.Rd b/man/Router.Rd index ec2a495..b1a3959 100644 --- a/man/Router.Rd +++ b/man/Router.Rd @@ -62,18 +62,18 @@ if(interactive()) \if{html}{\out{
Inherited methods
}} diff --git a/tests/testthat/_snaps/app.md b/tests/testthat/_snaps/app.md new file mode 100644 index 0000000..e7a1c38 --- /dev/null +++ b/tests/testthat/_snaps/app.md @@ -0,0 +1,8 @@ +# application + + Code + app + Message + -- Ambiorix ------------------------------------------------------ web server -- + * routes: 8 + diff --git a/tests/testthat/_snaps/cookie.md b/tests/testthat/_snaps/cookie.md new file mode 100644 index 0000000..eb1ab34 --- /dev/null +++ b/tests/testthat/_snaps/cookie.md @@ -0,0 +1,14 @@ +# Request cookie + + Code + parser + Message + i A cookie parser + +--- + + Code + cook + Message + i A cookie: hello = "world" + diff --git a/tests/testthat/_snaps/forward.md b/tests/testthat/_snaps/forward.md new file mode 100644 index 0000000..5fbe5c2 --- /dev/null +++ b/tests/testthat/_snaps/forward.md @@ -0,0 +1,7 @@ +# forward + + Code + f + Output + Using next method + diff --git a/tests/testthat/_snaps/log.md b/tests/testthat/_snaps/log.md new file mode 100644 index 0000000..48d05cb --- /dev/null +++ b/tests/testthat/_snaps/log.md @@ -0,0 +1,32 @@ +# log + + Code + success() + Output + + [1] v + +--- + + Code + error() + Output + + [1] x + +--- + + Code + info() + Output + + [1] i + +--- + + Code + warn() + Output + + [1] ! + diff --git a/tests/testthat/_snaps/request.md b/tests/testthat/_snaps/request.md new file mode 100644 index 0000000..9ced0cf --- /dev/null +++ b/tests/testthat/_snaps/request.md @@ -0,0 +1,52 @@ +# Request + + Code + req + Message + + -- A Request + * HEADERS: + text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9, + gzip, deflate, br, en-US,en;q=0.9, keep-alive, localhost:13698, " Not + A;Brand";v="99", "Chromium";v="99", ?0, "Linux", document, navigate, none, + ?1, 1, and Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like + Gecko) Chrome/99.0.4844.82 Safari/537.36 + * HTTP_ACCEPT: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" + * HTTP_ACCEPT_ENCODING: "gzip, deflate, br" + * HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.9" + * HTTP_CACHE_CONTROL: + * HTTP_CONNECTION: "keep-alive" + * HTTP_COOKIE: "" + * HTTP_HOST: "localhost:13698" + * HTTP_SEC_FETCH_DEST: "document" + * HTTP_SEC_FETCH_MODE: "navigate" + * HTTP_SEC_FETCH_SITE: "none" + * HTTP_SEC_FETCH_USER: "?1" + * HTTP_UPGRADE_INSECURE_REQUESTS: "1" + * HTTP_USER_AGENT: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 + (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36" + * httpuv.version 1.6.5 + * PATH_INFO: "/" + * QUERY_STRING: "" + * REMOTE_ADDR: "127.0.0.1" + * REMOTE_PORT: "44328" + * REQUEST_METHOD: "GET" + * SCRIPT_NAME: "" + * SERVER_NAME: "127.0.0.1" + * SERVER_PORT: "127.0.0.1" + * CONTENT_LENGTH: + * CONTENT_TYPE: + * HTTP_REFERER: + * rook.version: "1.1-0" + * rook.url_scheme: "http" + * params: "params" + Output + List of 1 + $ x: num 1 + Message + * query: "query" + Output + List of 1 + $ x: num 1 + diff --git a/tests/testthat/_snaps/response.md b/tests/testthat/_snaps/response.md new file mode 100644 index 0000000..1fc76a9 --- /dev/null +++ b/tests/testthat/_snaps/response.md @@ -0,0 +1,57 @@ +# response + + Code + res + Output + An ambiorix response + +# Response + + Code + res + Message + + -- A Response + +--- + + Code + print(robj(list(x = 1L))) + Message + i R object + Output + list(x = 1L) + $x + [1] 1 + + +--- + + Code + print(jobj(list(x = 1L))) + Message + i JSON object + Output + [1] "data" + +--- + + Code + res + Message + + -- A Response + + -- Headers + * HEADER Content-Type + Output + chr "tab-separated-values" + Message + * HEADER Content-Length + Output + num 17685 + Message + * HEADER xxx + Output + chr "hello" + diff --git a/tests/testthat/_snaps/router.md b/tests/testthat/_snaps/router.md new file mode 100644 index 0000000..37b4ad1 --- /dev/null +++ b/tests/testthat/_snaps/router.md @@ -0,0 +1,8 @@ +# rlication + + Code + r + Message + -- Ambiorix ---------------------------------------------------------- router -- + * routes: 8 + diff --git a/tests/testthat/_snaps/websocket.md b/tests/testthat/_snaps/websocket.md new file mode 100644 index 0000000..786c1ed --- /dev/null +++ b/tests/testthat/_snaps/websocket.md @@ -0,0 +1,16 @@ +# Websocket + + Code + ws + Message + i receive: `receive(message, ws)` + * Listening on message: + * name: "hello" + +--- + + Code + ws + Message + * send: `send(name, message)` +