Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectErrorCodes

Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Well-known validation error codes shared by the framework and its integrations.

public static class ValueObjectErrorCodes

Inheritance​

object ← ValueObjectErrorCodes

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

Codes are stable strings so they can safely cross process boundaries: they are surfaced in ProblemDetails responses, and each keys the message an application shows in its users' language, giving the key and the arguments the declared rules supply, which the MVC, minimal API and FluentValidation integrations look up. Consumers are free to define their own codes; these are only the ones the framework itself emits.

Fields​

InvalidFormat​

The value does not match the expected shape.

public const string InvalidFormat = "value_object.invalid_format"

Field Value​

string

NotAKnownValue​

The value does not belong to the closed set of values accepted by the type.

public const string NotAKnownValue = "value_object.not_a_known_value"

Field Value​

string

NotParsable​

The supplied text could not be converted to the underlying type.

public const string NotParsable = "value_object.not_parsable"

Field Value​

string

OutOfRange​

The value falls outside the accepted range.

public const string OutOfRange = "value_object.out_of_range"

Field Value​

string

Required​

A value was expected but none was supplied.

public const string Required = "value_object.required"

Field Value​

string

TooLong​

The value is longer than allowed.

public const string TooLong = "value_object.too_long"

Field Value​

string

TooShort​

The value is shorter than allowed.

public const string TooShort = "value_object.too_short"

Field Value​

string

Methods​

ToUpperSnakeCase(string)​

Maps a code to the upper snake case gRPC's error model takes as a reason: value_object.too_long becomes VALUE_OBJECT_TOO_LONG, and iban.check_digits becomes IBAN_CHECK_DIGITS.

public static string ToUpperSnakeCase(string errorCode)

Parameters​

errorCode string

The code, one of the framework's or one of your own.

Returns​

string

The code in upper snake case.

Remarks​

google.rpc.ErrorInfo.reason and google.rpc.BadRequest.FieldViolation.reason must match [A-Z][A-Z0-9_]+[A-Z0-9], and an ErrorInfo reason is at most 63 characters long, so a code such as value_object.too_long cannot be used as it is. Every service that maps a code through this method maps it the same way, and a client in another language branches on the result.

ASCII letters are upper-cased and ASCII digits kept. Any run of other characters, the dot and the underscore included, becomes one underscore, and an underscore left at either end is dropped. A code that cannot become a valid reason is refused rather than truncated or given a prefix, which would make two codes one.

Exceptions​

ArgumentNullException

errorCode is null.

ArgumentException

The code, once mapped, is no valid reason: it does not start with a letter, holds fewer than three letters, digits and underscores, or more than 63.