feat: provide a hook to customize validation errors
Metadata
Current evaluation
Merged PR #156 added CraftBaseModel.transform_pydantic_errors() and used it to provide clearer Project name and version validation messages; commit 1d91cd59.
Resolution: closed resolved
Reason: The approved PR was merged into the main branch as commit 1d91cd59, introducing the customization hook and its Project model validation-message updates.
Evaluated by: mr-cal-bot
No scores available.
Issue body
This commit adds a new transform_pydantic_errors() classmethod on CraftBaseModel to let subclasses customize/convert/translate Pydantic-generated error messages for fields that are specific to those subclasses.
This new "hook" is then used to update the error messages for the "name" and "version" fields of the Project class: instead of showing the raw "regex", we copy over Snapcraft's nice and user-friendly messages that fully describe what is and isn't allowed.
One caveat is that Pydantic 1.x's errors don't include the original (user-provided) value, so we can't use it on the message. We can fix this once we move to Pydantic 2.
This is related to https://github.com/canonical/rockcraft/issues/429
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #156 added CraftBaseModel.transform_pydantic_errors() and used it to provide clearer Project name and version validation messages; commit 1d91cd59. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #156 added CraftBaseModel.transform_pydantic_errors() and used it to improve validation messages for Project name and version fields. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged following two approvals and passing CI. Introduces a transform_pydantic_errors() hook in CraftBaseModel to customize Pydantic validation messages, improving user-facing errors for Project fields. Test coverage remains at 99.19%. |
Update history
No update history recorded yet.
Related work
-
Related To:
canonical/rockcraft#429
(confidence 100%)
The PR description explicitly identifies this Rockcraft issue as related.
Related issues
No related issues found above the similarity threshold.