Skip to content

Validation Results

A command or query result can contain validation items explaining why input was rejected or an operation could not proceed. Each item describes feedback, not the whole outcome: check the enclosing result for completion, authorization and exceptions as well.

An empty validation array does not by itself establish success. A local validation failure can return before the server is contacted, so a local authorization value is not evidence that the server granted access.

interface ValidationResult {
severity: ValidationResultSeverity;
message: string;
members: string[];
state: unknown;
reason: string;
reasonDetail?: string;
}

Use members to associate feedback with the affected fields. For example, this rule failure identifies the email field:

{
severity: ValidationResultSeverity.Error,
message: 'Email address is required',
members: ['email'],
state: null,
reason: 'rule'
}

This is a structural reference fragment, not a replacement for importing ValidationResult from @cratis/arc/validation. The runtime class defaults reason to rule.

reason is an open string set. Known values include rule, validatorFailed, dependencyUnavailable, malformedRequest, and frameworkFailure. Optional Chronicle integration can also produce concurrencyViolation and constraintViolation; these do not imply that standalone Arc uses an event store. reasonDetail identifies a finer cause where supplied. Do not match message prose to distinguish failures or reject unfamiliar reason strings.

frameworkFailure means the framework could not fulfill a command contract or complete its effects. It is framework-composed, and its message is not meant for end users.

When a required command property is undefined or null, the client returns reason: 'rule' with reasonDetail: 'Required' before contacting the server. Request parameters and optional properties are excluded. Import ValidationResultReasonDetail from @cratis/arc/validation and compare reasonDetail with ValidationResultReasonDetail.Required alongside reason === ValidationResultReason.Rule to supply your own copy. The message remains <propertyName> is required, and members contains the property name. This detail identifies the client check; server-side required-value validators do not currently supply it.

Show authored rule messages only when suitable for your audience; map framework diagnostics, including the client’s rule / Required results, to your own user-facing copy. state is application-authored metadata and must not contain secrets.

Severity classifies the item; it does not tell you whether the operation ultimately ran:

  • Error
  • Warning
  • Information
  • Unknown

For command execution filtering by severity, see Severity Filtering.