Skip to content

refactor!: rename fieldErrors to field_errors and stop leaking secrets in errors - #88

Open
edornd wants to merge 3 commits into
v2from
87-errors-tighten
Open

edornd wants to merge 3 commits into
v2from
87-errors-tighten

Conversation

@edornd

@edornd edornd commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Closes #87

Rejected-input errors could print secret values. Redaction decided whether a field was secret by looking up its type. When the lookup couldn't resolve the type, it treated the field as not secret. It also checked only the type at the error's path, so an error on a model or a list printed every secret inside it.

Now:

  • The lookup follows aliases, tuple positions and X | None. A path it can't resolve counts as secret. Errors inside a union member, where pydantic adds the member's name to the path, lose received.
  • Redaction checks whether the type holds a secret anywhere inside it. Secret[T] and type aliases count too.

Breaking changes:

  • The error document's fieldErrors key is now field_errors.
  • CommandError no longer has code, message, retryable, hint and exit_code attributes. Read them from error.report.

This also removes a private switch that printed pydantic's and argparse's own error text.

A rejected value is redacted when its field is a secret, but the type
lookup gave up in several cases and then treated the field as not
secret. An aliased SecretStr, a secret in a later tuple position, and
any field under an optional model or tuple printed the raw value.

The lookup now follows aliases, tuple positions and `X | None`, and a
path it still can't resolve counts as secret. Errors inside a union
member, where pydantic adds the member's name to the path, lose
`received`.

Refs #87
BREAKING CHANGE: the error document's `fieldErrors` key is now
`field_errors`, matching the snake_case keys inside each field error.

CommandError builds its report once and no longer copies its fields
onto the exception: read them from `error.report`. The report model
checks that the code is SCREAMING_CASE, so a bad code still raises
ValueError.

The private string-errors switch is gone, with the native text it
carried. The docs now use `field_errors`.

Closes #87
An error on a model, list or tuple reports the whole value as input, so
redaction now checks whether the type holds a secret anywhere inside it,
not only whether it is one. A model validator that rejects an object
with a password, or a too-long list of secrets, no longer prints them.
`Secret[T]` and `type` aliases of a secret count as secrets too.

Refs #87

This branch has not been deployed

No deployments
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 this pull request may close these issues.

1 participant