Skip to content

Commit

Permalink
Check for empty values when updating configuration attributes
Browse files Browse the repository at this point in the history
If a provided value for a configuration attribute is of length < 1,
throw an error.

In addition, adjust wrong error messages: Error messages are used generically,
independent of the concrete instance of the Conf class.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
  • Loading branch information
bockthom committed Apr 13, 2023
1 parent a6e001a commit 9f36c54
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions util-conf.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Conf = R6::R6Class("Conf",
#'
#' @return a named vector of logical values, named:
#' - existing,
#' - value.not.empty,
#' - type,
#' - allowed,
#' - allowed.number, and
Expand All @@ -109,15 +110,18 @@ Conf = R6::R6Class("Conf",
check.value = function(value, name) {
if (!exists(name, where = private[["attributes"]])) {
result = c(existing = FALSE)
} else if (length(value) < 1){
result = c(existing = TRUE, value.not.empty = FALSE)
} else {
## check all other properties
attribute = private[["attributes"]][[name]]
## if non-updatable field, return early
if (!is.null(attribute[["updatable"]]) && !attribute[["updatable"]]) {
result = c(existing = TRUE, updatable = FALSE)
result = c(existing = TRUE, value.not.empty = TRUE, updatable = FALSE)
} else {
result = c(
existing = TRUE,
value.not.empty = TRUE,
updatable = TRUE,
type = class(value) %in% attribute[["type"]],
## if 'allowed' is not defined for this attribute, any
Expand Down Expand Up @@ -219,22 +223,31 @@ Conf = R6::R6Class("Conf",
if (!check[["existing"]]) {

message = paste(
"Updating network-configuration attribute '%s' failed:",
"A network-configuraton attribute with this name does not exist."
"Updating configuration attribute '%s' failed:",
"A configuraton attribute with this name does not exist."
)
error.function(sprintf(message, name))

} else if (!check[["value.not.empty"]]) {

message = paste(
"Updating configuration attribute '%s' failed:",
"The provided value is empty!"
)
error.function(sprintf(message, name))

} else if (!check[["updatable"]]) {

message = paste(
"Updating network-configuration attribute '%s' failed:",
"Updating configuration attribute '%s' failed:",
"The value is not updatable!"
)
error.function(message, name)

} else {

message = paste0(
"Updating network-configuration attribute '%s' failed.\n",
"Updating configuration attribute '%s' failed.\n",
"Allowed values (%s of type '%s'): %s\n",
"Given value (of type '%s'): %s"
)
Expand Down

0 comments on commit 9f36c54

Please sign in to comment.