Skip to content

Commit

Permalink
fix: error handling on viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Jan 6, 2024
1 parent 2259a1e commit c56797c
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ document:

test:
Rscript -e "devtools::test()"

dev:
Rscript test.R
24 changes: 12 additions & 12 deletions man/Ambiorix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions man/Router.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# application

Code
app
Message
-- Ambiorix ------------------------------------------------------ web server --
* routes: 8

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/cookie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Request cookie

Code
parser
Message
i A cookie parser

---

Code
cook
Message
i A cookie: hello = "world"

7 changes: 7 additions & 0 deletions tests/testthat/_snaps/forward.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# forward

Code
f
Output
Using next method

32 changes: 32 additions & 0 deletions tests/testthat/_snaps/log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# log

Code
success()
Output
<cli_ansi_string>
[1] v

---

Code
error()
Output
<cli_ansi_string>
[1] x

---

Code
info()
Output
<cli_ansi_string>
[1] i

---

Code
warn()
Output
<cli_ansi_string>
[1] !

52 changes: 52 additions & 0 deletions tests/testthat/_snaps/request.md
Original file line number Diff line number Diff line change
@@ -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

57 changes: 57 additions & 0 deletions tests/testthat/_snaps/response.md
Original file line number Diff line number Diff line change
@@ -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"

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/router.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# rlication

Code
r
Message
-- Ambiorix ---------------------------------------------------------- router --
* routes: 8

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/websocket.md
Original file line number Diff line number Diff line change
@@ -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)`

0 comments on commit c56797c

Please sign in to comment.