# Error codes Every failure is a {py:class}`~ds_common_placeholder_py_lib.errors.PlaceholderError` with: - `code`: one of the codes below, an {py:class}`~ds_common_placeholder_py_lib.errors.ErrorCode`; - `path`: a JSON Pointer to the string that holds the placeholder (`""` for the value itself, `/a/0/b` inside it), relative to the value passed to `resolve`; - `placeholder`: the placeholder as written in the definition. For a `syntax` error it is input text that may be sensitive (for an unclosed `@{` it runs to the end of the string), so it is cut to 64 characters and `str(err)` and `repr(err)` leave it out; think twice before logging the attribute; - `message`: what went wrong; - `reference`: the reference whose value caused the error, as written (`owner.settings.region`, a whole namespace by its name), when one reference is at fault: its value is missing, `null` or blank, of the wrong type, or its namespace is not there. `None` when no one reference is: a function's own check (`@{get_hour, Mars/Base}`), a vault read, every `coalesce` argument missing, a table function finding no value; - `namespaces`: the namespaces the part that failed reads: the reference at fault, or the innermost call that failed with everything nested in it (not its sibling arguments), plus the namespace of `reference`. Set by `resolve` (SQL paths included, strict or not), alike for the same placeholder. Empty for an error found before anything is read (`syntax`, `lookup`'s own arguments, a SQL position, a secret call in SQL), and from `validate`. - `reference` is hidden and scrubbed as `placeholder` is. The message never contains a resolved value, so `str(err)` is safe to put in a failure event or a log line. `validate` returns a list of these. `resolve` raises the first one; its `path` is a JSON Pointer into the context (`/dataset/settings/from`). Map `validate` errors to "definition rejected" and resolution errors to "execution failed" (§12). Which side a failure is on: - **The service:** `secret_unavailable` (the vault cannot be read), and failures of what the service itself put in the context. These share their codes with input problems, so tell them apart by the message, which is kept stable: | Cause | Code | Message | | --- | --- | --- | | A provider or namespace function raises | `missing_value` | `provider failed ()` | | A provider returns a value that is not JSON | `type` | `a is not a JSON value`, `value is not a finite number`, `object key is not a string` | Retry these or report them as the service's (a dispatcher: 503). Plain JSON objects never raise or return non-JSON, so a dispatcher whose context holds only those sees none of them but `secret_unavailable`. A value the service put in the context that a function refuses (a time that is not RFC 3339, read from `run.logical_at`) is `argument` naming that value as `reference`: tell it from a definition error by that reference. - **The input:** everything else: the definition, the values it reads, or the secret stored for it (`type` for a stored secret that is not UTF-8). Retrying does not help (a dispatcher: 400). | Code | Meaning | Example | | --- | --- | --- | | `syntax` | Malformed placeholder: unclosed, empty, bad name or path, a nested placeholder that is not a whole argument or is more than 16 deep, or a placeholder in an object key | `@{lookup, owner.settings.x`, `@{f, a@{x}}` | | `unknown_namespace` | The namespace was not passed to the context (checked at resolution) | `@{lookup, env.HOME}`, `@{lookup, execution.id}` in silver | | `unknown_function` | Not in the registry | `@{new_uuid4}` | | `arity` | Wrong number of arguments | `@{get_secret}` | | `argument` | Bad argument: unknown timezone, language not `EN`/`NO`, a non-string argument, a `coalesce` literal before the last argument or blank, or a time that is not RFC 3339 | `@{get_hour, Mars/Base}` | | `missing_value` | `null`, empty, blank, or no such path; every `coalesce` argument missing; an undeclared variable; a function argument read from a reference with no value | `@{lookup, owner.settings.missing}` | | `type` | An object or array embedded in text; a non-JSON value from a provider; a non-UTF-8 secret | `"a-@{lookup, owner.settings.tags}"` | | `secret_scope` | The `get_secret` key's tenant segment is not the context's tenant (exact match: an uppercase UUID is another tenant), or the key has none | another tenant's path, `db/url` | | `secret_missing` | ds-vault has no such key | | | `secret_unavailable` | The vault cannot be read: `VAULT_DATABASE_URL` is not set, or a connection, IAM, or KMS failure. A service problem, not the definition's | | | `sql_position` | Placeholder inside a SQL string, quoted identifier, or comment, or glued to another token | `WHERE a = '@{x}'` | | `protected_field` | `@{` (even inside a quoted text) in a protected key (by default `id`, `name`, `type`, or `version`), or in any string or key inside them, outside a `settings` key; checked by `validate` | `"name": "@{lookup, variables.env}-load"` | | `sql_secret` | A `get_secret` or `secret` call in SQL, or a value containing a secret this context read | `SELECT @{get_secret, …}` | | `cycle` | A value in the context is read again while it is being resolved, or values are read inside one another more than 64 deep | `"a": "@{lookup, variables.b}"`, `"b": "@{lookup, variables.a}"` | ```python from ds_common_placeholder_py_lib import ErrorCode, PlaceholderError try: settings = ctx.resolve("dataset.settings") except PlaceholderError as err: if err.code is ErrorCode.SECRET_SCOPE: alert_security(err.path) publish_stage_failed(code=err.code.value, message=str(err)) ``` ## Who is at fault A failure about a value is the fault of whoever supplies that value. Tell them apart with `reference` and `namespaces`, never by searching the placeholder text: a quoted literal can look like a reference, and one placeholder can read several namespaces. ```python VALUE_CODES = {ErrorCode.MISSING_VALUE, ErrorCode.TYPE, ErrorCode.ARGUMENT, ErrorCode.SECRET_SCOPE, ErrorCode.SECRET_MISSING} def reads_only(err: PlaceholderError, namespace: str) -> bool: """The failure is about a value of *namespace*, and nothing else's.""" if err.code not in VALUE_CODES: return False if err.reference is not None: return err.reference.partition(".")[0] == namespace return err.namespaces == {namespace} ``` - First take out the service's failures: `secret_unavailable`, a message starting `provider failed`, and a `reference` to a run fact the request should carry (`run.logical_at`, `run.job_id`, …). - Then, in a pipeline, `reads_only(err, "owner")` is the owner's data at fault: the owner lacks a value or holds a wrong one. Anything else with an input code is the definition's: a misspelt variable is `missing_value` too, but its `reference` is `variables.…`. - `reads_only` points at the owner, but the definition may still be the one to fix. The library cannot tell these apart, so show the `reference` and `path` to whoever fixes it: - a misspelt owner key (`owner.settings.owner_dbid`) is `missing_value` on an owner path, as if the owner lacked it; - `@{lookup, owner.settings.address}` in SQL is `type`: either the owner holds an object where the definition expects text, or the definition reads the wrong key; - a function's own check on a call that reads the owner, such as a bad literal index in `@{get_value_from_dataframe, abc, a, owner.settings.rows}`, has no `reference` and `namespaces` `{owner}`; - a `coalesce` whose value is an owner's object, put in text or SQL (`x @{coalesce, owner.settings.address, variables.v}`), is `type` with no `reference` and the namespaces of every `coalesce` argument, so the rule calls it the definition's. A pipeline job runs for one owner, so any failure fails the stage request; see [the pipeline section of services](services.md#pipeline-stage-dispatchers).