Learn R Programming

climatehealth (version 1.0.0)

abort_climate: Raise a typed error with structured metadata

Description

Creates a classed condition that can be caught and inspected by the API layer. This is the base helper - prefer using specific helpers like abort_column_not_found() or abort_validation() when applicable.

Usage

abort_climate(message, type = "generic_error", ..., call = rlang::caller_env())

Value

Never returns; always raises an error.

Arguments

message

Human-readable error message

type

Error type for classification. One of:

  • "validation_error": Data/parameter validation issues (HTTP 400)

  • "column_not_found": Missing column in dataset (HTTP 400)

  • "model_error": Statistical model failures (HTTP 422)

  • "generic_error": Unclassified errors (HTTP 500)

...

Additional metadata to include in the error (e.g., column = "tmean")

call

The call to include in the error (defaults to caller's call)

Examples

Run this code
# \donttest{
# Basic usage
err <- tryCatch(
  abort_climate("Something went wrong", "generic_error"),
  error = identity
)
inherits(err, "climate_error")

# With metadata
err <- tryCatch(
  abort_climate(
    "Invalid lag value",
    "validation_error",
    param = "nlag",
    value = -1,
    expected = "non-negative integer"
  ),
  error = identity
)
err$type
# }

Run the code above in your browser using DataLab