Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# getRad (development version)

* Make error messages more consistent (#146).
* Restore access to Estonian data.
* Prevent leaving temporary files for downloading Dutch polar volume data (#148).

# getRad 0.2.3
Expand Down
21 changes: 10 additions & 11 deletions R/get_pvol.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
check_odim_nexrad(radar)
if (anyDuplicated(radar)) {
cli::cli_abort(
"The argument {.arg radar} contains duplications these should be removed.",
"{.arg radar} contains duplications that must be removed.",
class = "getRad_error_radar_duplicated"
)
}
if (inherits(datetime, "POSIXct") && length(datetime) == 2) {
if (any(duplicated(datetime))) {
cli::cli_abort(
"When providing two {.cls POSIXct} as a {.arg datetime}
they should differ to represent an inverval.",
"{.arg datetime} contains duplicate {.cls POSIXct}. Values must differ
to represent an interval.",
class = "getRad_error_duplicated_timestamps"
)
}
Expand All @@ -61,9 +61,8 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
!rlang::is_scalar_vector(datetime)
) {
cli::cli_abort(
"The argument {.arg datetime} to the {.fn get_pvol} function
should be a single {.cls POSIXct} or a {.cls interval}.
The later can also be specified by two {.cls POSIXct}.",
"{.arg datetime} should be a single {.cls POSIXct} or a {.cls interval}.
The latter can also be specified by two {.cls POSIXct}.",
class = "getRad_error_time_not_correct"
)
}
Expand All @@ -88,10 +87,10 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
if (lubridate::is.interval(datetime)) {
if (lubridate::as.duration(datetime) > lubridate::hours(1)) {
cli::cli_warn(
"The interval specified for {.arg datetime} ({.val {lubridate::int_start(datetime)}}-{.val {lubridate::int_end(datetime)}}) likely results
in many polar volumes, when loading that may polar
volumes at the same time computational issues frequently
occur.",
"{.arg datetime} represent an interval ({.val
{lubridate::int_start(datetime)}}-{.val {lubridate::int_end(datetime)}})
that likely covers many polar volumes. Computational issues can occur
when loading that many polar volumes at the same time.",
class = "getRad_warn_many_pvols_requested"
)
}
Expand Down Expand Up @@ -148,7 +147,7 @@ select_get_pvol_function <- function(radar, ..., call = rlang::caller_env()) {
))
if (rlang::is_na(fun)) {
cli::cli_abort(
"No suitable function exist downloading from the radar {.val {radar}}",
"No suitable function exist to download data for radar {.val {radar}}.",
class = "getRad_error_no_function_for_radar_with_country_code",
call = call
)
Expand Down
9 changes: 5 additions & 4 deletions R/get_pvol_de.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ get_pvol_de <- function(radar, time, ..., call = rlang::caller_env()) {
if (nrow(files_to_get) != 50) {
cli::cli_abort(
c(
x = "The server returned an unexpected number of files.",
i = "In many cases this because no data is available for the time requested. For Germany only the last three days are available.",
i = "Alternatively there is an unstable connection or temporal error in the German data provided."
"The server returned an unexpected number of files.",
"i" = "In many cases this because no data are available for the time
requested. For Germany only the last three days are available.
The error can also be caused by an unstable connection or
temporal error in the German data provided."
),

class = "getRad_error_germany_unexpected_number_of_files",
call = call
)
Expand Down
8 changes: 4 additions & 4 deletions R/get_pvol_ee.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ get_pvol_ee <- function(radar, time, ..., call = rlang::caller_env()) {
list(
greaterThanOrEqual = list(
field = "Timestamp",
value = strftime(time, "%Y-%m-%dT%H:%M:%OS6%z")
value = strftime(time, "%FT%TZ", tz = 'UTC')
)
),
list(
lessThanOrEqual = list(
field = "Timestamp",
value = strftime(time, "%Y-%m-%dT%H:%M:%OS6%z")
value = strftime(time, "%FT%TZ", tz = "UTC")
)
)
)
Expand All @@ -62,7 +62,7 @@ get_pvol_ee <- function(radar, time, ..., call = rlang::caller_env()) {
)
)
files <- httr2::request(
"https://avaandmed.keskkonnaportaal.ee/_vti_bin/RmApi.svc/active/items/query"
"https://avaandmed.keskkonnaportaal.ee/api/lists/active/items/query"
) |>
req_user_agent_getrad() |>
httr2::req_body_json(json_list) |>
Expand All @@ -71,7 +71,7 @@ get_pvol_ee <- function(radar, time, ..., call = rlang::caller_env()) {
httr2::resp_body_json()
if (files$numFound == 0 || length(files$documents) != 1) {
cli::cli_abort(
"The expected number of files is not found",
"The expected number of files is not found.",
class = "getRad_error_get_pvol_ee_differing_n_files"
)
}
Expand Down
22 changes: 15 additions & 7 deletions R/get_pvol_nl.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ get_pvol_nl <- function(radar, time, ..., call = rlang::caller_env()) {
httr2_http_403 = function(cnd) {
cli::cli_abort(
c(
"There was an authorization error, possibly this relates to using an invalid API key",
i = "Please check if you set the correct `nl_api_key` with {.code get_secret('nl_api_key')}"
"There was an authorization error. You may have used an invalid API
key.",
"i" = "Please check if you set the correct {.val nl_api_key} with
{.code get_secret(\"nl_api_key\")}."
),
cnd = cnd,
class = "getRad_error_get_pvol_nl_authorization_failure",
Expand All @@ -59,11 +61,17 @@ get_pvol_nl <- function(radar, time, ..., call = rlang::caller_env()) {
if (converter == "") {
cli::cli_abort(
c(
x = "The program to convert KNMI data to ODIM format is not found.",
i = "The source code for this binary can be obtained from this location {.file {system.file('extra/KNMI_vol_h5_to_ODIM_h5.c', package='getRad')}}",
i = "Please compile the binary and include it in the search path as a program named {.arg KNMI_vol_h5_to_ODIM_h5}",
i = "On linux systems this can be done with the following command {.code h5cc KNMI_vol_h5_to_ODIM_h5.c -o KNMI_vol_h5_to_ODIM_h5}.",
i = "If another name is used or the program is not in the search path use options to locate the program ({.run options(getRad.nl_converter='')})."
"The program to convert KNMI data to the ODIM format can't be found.",
"i" = "The source code for this binary can be obtained from {.file
{system.file(\"extra/KNMI_vol_h5_to_ODIM_h5.c\",
package=\"getRad\")}}.",
"i" = "Please compile the binary and include it in the search path as
a program named {.val KNMI_vol_h5_to_ODIM_h5}. On linux systems
this can be done with the command {.code h5cc
KNMI_vol_h5_to_ODIM_h5.c -o KNMI_vol_h5_to_ODIM_h5}. If another
name is used or the program is not in the search path, use
options to locate the program ({.code
options(getRad.nl_converter=\"\")})."
),
class = "getRad_error_no_nl_converter_found",
call = call
Expand Down
7 changes: 4 additions & 3 deletions R/get_pvol_se.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ get_pvol_se <- function(radar, time, ..., call = rlang::caller_env()) {
httr2_http_404 = function(cnd) {
cli::cli_abort(
c(
x = "No polar volume data could be found for {.val {radar}} at time {.val {time}}",
i = "Volume data in Sweden is only available for 24 hours",
i = "If the requested time is within the last 24 hours the error might relate to a server outage or package problem"
"Can't find polar volume data for {.val {radar}} at {.val {time}}.",
"i" = "Polar volume data in Sweden is only available for 24 hours.
If the requested time is within the last 24 hours the error
might relate to a server outage or package problem."
),
parent = cnd,
call = call,
Expand Down
8 changes: 4 additions & 4 deletions R/get_pvol_us.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_pvol_us <- function(radar, datetime, ..., call = rlang::caller_env()) {
httr2::req_perform(path = file, error_call = call),
httr2_http_404 = function(cnd) {
cli::cli_abort(
"NEXRAD file not found at {.url {url}}.",
"Can't find NEXRAD file at {.url {url}}.",
call = call,
cnd = cnd,
class = "getRad_error_us_file_not_found"
Expand Down Expand Up @@ -48,8 +48,7 @@ get_pvol_us <- function(radar, datetime, ..., call = rlang::caller_env()) {
d <- as.Date(date, tz = "UTC")
if (!rlang::is_scalar_character(radar)) {
cli::cli_abort(
"Radar should be a character of length one as otherwise not all
key date combinations might be tried",
"{.arg radar} must be single radar code.",
class = "getRad_error_pvol_us_radar_not_scalar",
call = call
)
Expand Down Expand Up @@ -145,7 +144,8 @@ get_pvol_us <- function(radar, datetime, ..., call = rlang::caller_env()) {
)
if (!length(ts)) {
cli::cli_abort(
"No scans found for {.val {radar}} near {.val {format(datetime, '%F %T %Z')}}",
"Can't find scans for radar {.val {radar}} near {.val {format(datetime,
\"%F %T %Z\")}}.",
class = "getRad_error_us_no_scan_found",
call = call
)
Expand Down
32 changes: 12 additions & 20 deletions R/get_vpts.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ get_vpts <- function(
if (missing(source)) {
source <- "baltrad"
}
supported_sources <- eval(rlang::fn_fmls()$source)

if (is.null(source)) {
# providing NULL isn't allowed either
cli::cli_abort(
glue::glue(
"Please provide a value for the source argument:
possible values are {possible_sources}.",
possible_sources = glue::glue_collapse(
glue::backtick(eval(rlang::fn_fmls()$source)),
sep = ", ",
last = " or "
)
c(
"{.arg source} must be provided.",
"i" = "Supported sources: {.val {supported_sources}}."
),
class = "getRad_error_source_missing"
)
Expand All @@ -92,7 +89,7 @@ get_vpts <- function(
## the enumeration in the function definition.
if (length(source) > 1) {
cli::cli_abort(
"Only one source can be queried at a time.",
"{.arg source} must be a single character value.",
class = "getRad_error_multiple_sources"
)
}
Expand All @@ -101,17 +98,11 @@ get_vpts <- function(

# Get the default value of the source arg, even if the user provided
# a different value.
supported_sources <- eval(formals()$source)
if (!source %in% supported_sources) {
cli::cli_abort(
glue::glue(
"Invalid source {glue::backtick(source)} provided. Possible values are:
{possible_sources}.",
possible_sources = glue::glue_collapse(
glue::backtick(supported_sources),
sep = ", ",
last = " or "
)
c(
"{.arg source} {.val {source}} is invalid.",
"i" = "Supported sources: {.val {supported_sources}}."
),
class = "getRad_error_source_invalid"
)
Expand All @@ -120,7 +111,7 @@ get_vpts <- function(
# Check that the provided radar argument is a character vector
if (!is.character(radar)) {
cli::cli_abort(
"Radar argument must be a character vector.",
"{.arg radar} must be a character vector.",
class = "getRad_error_radar_not_character"
)
}
Expand All @@ -132,7 +123,8 @@ get_vpts <- function(
!lubridate::is.interval(datetime)
) {
cli::cli_abort(
"{.arg datetime} argument must be a {.cls character}, {.cls POSIXct}, {.cls Date}, or {.cls Interval} object.",
"{.arg datetime} must be a {.cls character}, {.cls POSIXct}, {.cls Date},
or {.cls Interval} object.",
class = "getRad_error_date_parsable"
)
}
Expand Down
11 changes: 5 additions & 6 deletions R/get_vpts_aloft.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ get_vpts_aloft <- function(
if (!all(radar_odim_code %in% coverage$radar)) {
missing_radar <- radar_odim_code[!radar_odim_code %in% coverage$radar]
cli::cli_abort(
"Radar not found in ALOFT coverage:
{missing_radar}.",
"Can't find radar {.val {missing_radar}} in the coverage file (see
{.fun get_vpts_coverage}).",
missing_radar = missing_radar,
class = "getRad_error_aloft_radar_not_found"
)
Expand All @@ -60,7 +60,7 @@ get_vpts_aloft <- function(

if (!at_least_one_radar_date_combination_exists) {
cli::cli_abort(
"No data found for the requested radar(s) and date(s).",
"Can't find any data for the requested radar(s) and date(s).",
class = "getRad_error_date_not_found"
)
}
Expand All @@ -77,9 +77,8 @@ get_vpts_aloft <- function(

if (!all(radar_odim_code %in% coverage$radar)) {
cli::cli_abort(
"{length(missing_radars)} Radar{?s} not found in {source} coverage:
{glue::backtick(missing_radars)}",
missing_radars = missing_radars,
"Can't find radar{?s} {.val {missing_radars}} in the coverage file (see
{.fun get_vpts_coverage}).",
class = "getRad_error_radar_not_found"
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/get_vpts_coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ get_vpts_coverage <- function(

if (length(source) == 0) {
cli::cli_abort(
"Source should atleast have one value.",
"{.arg source} must have at least one value.",
class = "getRad_error_length_zero"
)
}
Expand Down
8 changes: 4 additions & 4 deletions R/get_vpts_coverage_rmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ get_vpts_coverage_rmi <- function(

if (any(!radar %in% found_radars)) {
cli::cli_abort(
"Requested radar {radar[!radar %in% found_radars]} not
present in RMI coverage",
"Can't find radar {.val {radar[!radar %in% found_radars]}} in the coverage
file (see {.fun get_vpts_coverage}.",
call = call
)
}
Expand All @@ -69,8 +69,8 @@ get_vpts_coverage_rmi <- function(

if (!all(year %in% years_covered_by_rmi) && use_year_filter) {
cli::cli_abort(
"Requested year {year[!year %in% years_covered_by_rmi]}
not present in RMI coverage",
"Can't find year {.val {year[!year %in% years_covered_by_rmi]}} in the
coverage file (see {.fun get_vpts_coverage}).",
class = "getRad_error_date_not_found",
call = call
)
Expand Down
3 changes: 1 addition & 2 deletions R/get_weather_radars.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ get_weather_radars <- function(
!rlang::is_character(source) || any(is.na(source)) || length(source) == 0
) {
cli::cli_abort(
"{.arg source} is not valid, it should be an {.cls character}
vector with a length of atleast one not contain NA values.",
"{.arg source} must be a character (vector).",
class = "getRad_error_weather_radar_source_not_character"
)
}
Expand Down
12 changes: 6 additions & 6 deletions R/secrets.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set_secret <- function(name, secret = NULL) {
rlang::check_installed("keyring", "to manage secrets in getRad")
if (!rlang::is_scalar_character(name)) {
cli::cli_abort(
"{.arg name} should be a scalar character",
"{.arg name} must be a single character value.",
class = "getRad_error_set_secret_no_scalar_character"
)
}
Expand All @@ -38,7 +38,7 @@ set_secret <- function(name, secret = NULL) {
getOption(
"getRad.key_prefix",
default = cli::cli_abort(
"The option `getRad.key_prefix` is not found",
"Can't find the option {.val getRad.key_prefix}.",
class = "getRad_error_key_prefix_not_found_setting"
)
),
Expand All @@ -65,15 +65,15 @@ get_secret <- function(name) {
rlang::check_installed("keyring", "to manage secrets in getRad")
if (!rlang::is_scalar_character(name)) {
cli::cli_abort(
"{.arg name} should be a scalar character",
"{.arg name} must be a single character value.",
class = "getRad_error_get_secret_no_scalar_character"
)
}
sname <- paste0(
getOption(
"getRad.key_prefix",
default = cli::cli_abort(
"The option `getRad.key_prefix` is not found",
"Can't find the option {.val getRad.key_prefix}.",
class = "getRad_error_key_prefix_not_found_getting"
)
),
Expand All @@ -82,8 +82,8 @@ get_secret <- function(name) {
if (!(sname %in% keyring::key_list(sname)$service)) {
cli::cli_abort(
c(
x = "The {.arg {sname}} secret is not in the keyring.",
i = 'Please use {.code set_secret("{name}")} to store the secret.'
"Can't find secret {.arg {sname}} in the keyring.",
"i" = "Please use {.code set_secret(\"{name}\")} to store the secret. Note that the prefix is automatically added in {.fun set_secret}."
),
class = "getRad_error_secret_not_found"
)
Expand Down
Loading