Skip to main content

Typed validation error handling

Handle an expected validation category without relying on error-message wording. Every example deliberately rejects an oversized button label.

Output

Local preview of the selected language’s tested example. Slack client appearance may differ; controls here do not send requests.

Validation handled
length-exceeded · the oversized button label was rejected before sending.
Serialized output
{
"category": "length-exceeded",
"handled": true
}

Code​

Catch LengthError for a label-length failure; catch InvalidUsageError for any slackblocks validation failure. Do not classify failures by matching their message text.

import json
from slackblocks import Button, LengthError

try:
Button(text="x" * 100, action_id="approve")
except LengthError:
print(json.dumps({"category": "length-exceeded", "handled": True}))
else:
raise AssertionError("Expected a button label length error")