-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mrc-ide/mrc-5524
Add unique codes for each error message
- Loading branch information
Showing
13 changed files
with
437 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(cnd_footer,odin_parse_error) | ||
export(odin_error_explain) | ||
importFrom(rlang,cnd_footer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
url: https://mrc-ide.github.io/dust2 | ||
|
||
template: | ||
bootstrap: 5 | ||
|
||
reference: | ||
- title: All functions | ||
desc: >- | ||
All functions, until the API starts to develop properly. | ||
contents: | ||
- odin_error_explain | ||
|
||
articles: | ||
- title: Details | ||
navbar: Details | ||
contents: | ||
- errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
codecov | ||
etc | ||
io | ||
odin | ||
odin's |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
read_errors <- function() { | ||
path_rmd <- "vignettes/errors.Rmd" | ||
txt <- readLines(path_rmd) | ||
|
||
re <- "^# `(E[0-9]{4})`$" | ||
i <- grep(re, txt) | ||
if (length(setdiff(grep("^# ", txt), i)) > 0) { | ||
stop("Some headings don't match expected pattern") | ||
} | ||
|
||
f <- function(from, to) { | ||
ret <- txt[from:to] | ||
while (ret[[1]] == "") { | ||
ret <- ret[-1] | ||
} | ||
while (ret[[length(ret)]] == "") { | ||
ret <- ret[-length(ret)] | ||
} | ||
ret | ||
} | ||
|
||
ret <- Map(f, i + 1, c(i[-1] - 1, length(txt))) | ||
names(ret) <- sub(re, "\\1", txt[i]) | ||
ret | ||
} | ||
|
||
|
||
## We might parse this further, e.g., with commonmark, so that we can | ||
## render this nicely to the console as cli would make this pretty | ||
## easy really. | ||
errors <- read_errors() | ||
save(list = "errors", file = file.path("R/sysdata.rda"), version = 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
test_that("can explain an error", { | ||
skip_if_not_installed("mockery") | ||
mock_browse <- mockery::mock() | ||
mockery::stub(odin_error_explain, "utils::browseURL", mock_browse) | ||
odin_error_explain("E0001") | ||
mockery::expect_called(mock_browse, 1) | ||
expect_equal( | ||
mockery::mock_args(mock_browse)[[1]], | ||
list("https://mrc-ide.github.io/odin2/articles/errors.html#e0001")) | ||
}) | ||
|
||
|
||
test_that("error if given invalid code", { | ||
msg <- "Invalid code 'E001', should match 'Exxxx'" | ||
expect_error(odin_error_explain("E001"), | ||
"Invalid code 'E001', should match 'Exxxx'") | ||
expect_error(odin_error_explain("e0001"), | ||
"Invalid code 'e0001', should match 'Exxxx'") | ||
expect_error(odin_error_explain("E00001"), | ||
"Invalid code 'E00001', should match 'Exxxx'") | ||
expect_error(odin_error_explain("anything"), | ||
"Invalid code 'anything', should match 'Exxxx'") | ||
}) | ||
|
||
|
||
test_that("error if given unknown code", { | ||
expect_error( | ||
odin_error_explain("E9999"), | ||
"Error 'E9999' is undocumented") | ||
}) |
Oops, something went wrong.