Skip to content

overhaul action levels to log levels #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kmasiello opened this issue Feb 21, 2025 · 2 comments · May be fixed by #611
Open

overhaul action levels to log levels #604

kmasiello opened this issue Feb 21, 2025 · 2 comments · May be fixed by #611

Comments

@kmasiello
Copy link

Action levels are more appropriately described as flags or threshold levels. Align flags with log levels for further downstream actions.

warn_at-> warn
stop_at -> error
notify_at -> critical

Aligns with decisions made in python pointblank. posit-dev/pointblank#69

@rich-iannone
Copy link
Member

Thanks for the issue! Yeah, this should absolutely be done. It's a breaking change like in py-pointblank but the R version has had W/S/N for years so this'll have to be more like a staged migration.

@hfrick hfrick mentioned this issue Mar 6, 2025
3 tasks
@yjunechoe
Copy link
Collaborator

yjunechoe commented Mar 18, 2025

As a first step towards deprecation, without touching too much internal code, I can imagine re-writing action_levels() to be something like:

 action_levels <- function(
+    warn = NULL,
+    error = NULL,
+    critical = NULL,
+    fns = NULL,
+    ...,
     warn_at = NULL,
     stop_at = NULL,
-    notify_at = NULL,
-    fns = NULL
+    notify_at = NULL
 ) {

+  # Gradual argument name deprecation
+  ## Deprecation message
+  if (!missing(warn_at) || !missing(stop_at) || !missing(notify_at)) {
+    cli::cli_inform(
+      c("!" = "Arguments `warn_at`, `stop_at`, and `notify_at` are deprecated.",
+        " " = "Please use `warn`, `error`, and `critical` instead."),
+      .frequency = "always",
+      .frequency_id = "pointblank-action-levels-args-deprecation"
+    )
+  }
+  ## Guard partial matching and redundant args
+  rlang::check_dots_empty()
+  rlang::check_exclusive(warn, warn_at, .require = FALSE)
+  rlang::check_exclusive(error, stop_at, .require = FALSE)
+  rlang::check_exclusive(critical, notify_at, .require = FALSE)
+  ## Resolve names
+  warn <- warn %||% warn_at
+  error <- error %||% stop_at
+  critical <- critical %||% notify_at
+
   fns <- normalize_fns_list(fns = fns)

-  warn_list <- normalize_fraction_count(warn_at)
-  stop_list <- normalize_fraction_count(stop_at)
-  notify_list <- normalize_fraction_count(notify_at)
+  warn_list <- normalize_fraction_count(warn)
+  stop_list <- normalize_fraction_count(error)
+  notify_list <- normalize_fraction_count(critical)

  # <rest of function>

Something like this would ensure backwards compatibility for both positional and named arguments, but throw a deprecation message if matched by name. And while both name variants are active, we'd throw an error if both are redundantly supplied. I'll dig around more for whether a similar problem had been solved more cleanly before!


Other than that, stop_on_fail(stop_at) and warn_on_fail(warn_at) are the 2 other user-facing functions that would need the name change. Maybe we can revisit that in a separate issue once we know what to do with action_levels()

@yjunechoe yjunechoe linked a pull request Mar 25, 2025 that will close this issue
27 tasks
@yjunechoe yjunechoe linked a pull request Mar 25, 2025 that will close this issue
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants