Skip to content

Normalize template variable validation errors beyond enum checks #167

Closed

Description

@httpdss

Summary

The enum validation cleanup improves one class of template variable error, but other schema validation failures in TemplateRenderer._coerce_and_validate still raise plain ValueError. Regex, min, and max validation failures should use the same domain error path so the CLI consistently reports clean messages.

Evidence from code inspection

In structkit/template_renderer.py:

  • Type coercion errors and enum errors now use TemplateVariableError.
  • Regex validation still raises plain ValueError:
    • Variable '{name}' does not match required pattern: {pattern}
  • Min/max validation still raises plain ValueError:
    • Variable '{name}' must be >= {minv}, got {coerced}
    • Variable '{name}' must be <= {maxv}, got {coerced}

GenerateCommand.execute catches TemplateVariableError, not every ValueError, so these user-caused schema validation failures can still surface as tracebacks.

Proposed fix

  • Convert regex/min/max validation failures to TemplateVariableError.
  • Consider a helper for all variable validation message formatting.
  • Keep catching only the domain error at the command boundary, not broad Exception.

Acceptance criteria

  • Invalid regex-pattern value exits 1 with no Traceback.
  • Below-min and above-max numeric values exit 1 with no Traceback.
  • Error messages include variable name, expected constraint, and received value.
  • Tests cover regex, min, and max validation through both TemplateRenderer and structkit generate.

Activity

  1. added a commit that references this issue on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions