Skip to main content

ValidationError

Struct ValidationError 

Source
pub struct ValidationError { /* private fields */ }
Expand description

A validation error is a Serializable object that contains the path where the validation error of a certain kind ocurred, and an optional and arbitrary piece of meta-information.

Implementations§

Source§

impl ValidationError

Source

pub fn kind(&self) -> &ValidationErrorKind

Source

pub fn message(&self) -> &str

Source§

impl ValidationError

Source

pub fn unexpected_runtime_error(message: String) -> Self

Creates an ValidationErrorKind::UnexpectedRuntimeError kind of error when something unexpected happen at runtime after a query was properly validated by the parser against the schema.

Source

pub fn empty_selection( selection_path: Vec<&str>, output_type_description: OutputTypeDescription, ) -> Self

Creates an ValidationErrorKind::EmptySelection kind of error, which happens when the selection of fields is empty for a query.

Example json query:

{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: {} } }

Source

pub fn invalid_argument_type( selection_path: Vec<&str>, argument_path: Vec<&str>, argument_description: ArgumentDescription<'_>, inferred_argument_type: String, ) -> Self

Creates an ValidationErrorKind::InvalidArgumentType kind of error, which happens when the argument is of a type that is incompatible with its definition.

Say the schema type for user.id is Int

The example json query will fail, as it’s trying to pass a string instead.

{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “id”: “a22b8732-be32-4a30-9b38-78843aaa48f8” } }, “selection”: { “$scalars”: true } } }

Source

pub fn invalid_argument_value( selection_path: Vec<&str>, argument_path: Vec<&str>, value: String, expected_argument_type: &str, underlying_err: Option<Box<dyn Error>>, ) -> Self

Creates an ValidationErrorKind::InvalidArgumentValue kind of error, which happens when the argument is of the correct type, but its value is invalid, said a negative number on a type that is integer but which values should be non-negative. Or a uuid which type is correctly a string, but its format is not the appropriate.

Say the schema type for user.id is Int

The example json query will fail, as it’s trying to pass a string instead.

{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “dob”: “invalid date” } }, “selection”: { “$scalars”: true } } }

Source

pub fn some_fields_missing( selection_path: Vec<&str>, argument_path: Vec<&str>, min_field_count: Option<usize>, max_field_count: Option<usize>, required_fields: Option<Vec<Cow<'_, str>>>, provided_field_count: usize, input_type_description: &InputTypeDescription, ) -> Self

Creates an ValidationErrorKind::SomeFieldsMissing kind of error, which happens when there are some fields missing from a query

Source

pub fn too_many_fields_given( selection_path: Vec<&str>, argument_path: Vec<&str>, min_field_count: Option<usize>, max_field_count: Option<usize>, required_fields: Option<Vec<Cow<'_, str>>>, provided_field_count: usize, input_type_description: &InputTypeDescription, ) -> Self

Creates an ValidationErrorKind::SomeFieldsMissing kind of error, which happens when there are more fields given than the ones a type accept

Source

pub fn required_argument_missing( selection_path: Vec<&str>, argument_path: Vec<&str>, input_type_descriptions: &[InputTypeDescription], ) -> Self

Creates an ValidationErrorKind::RequiredArgumentMissing kind of error, which happens when there is a missing argument for a field missing, like the where field below.

Example json query:

{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: {} } }

Source

pub fn conditionally_required_argument_missing( selection_path: &[&str], argument_path: &[&str], dependent_argument_path: &[&str], input_type_descriptions: &[InputTypeDescription], ) -> Self

Creates a ValidationErrorKind::RequiredArgumentMissing kind of error for a conditionally required argument which needs to be present in the current query because another argument which depends on it was provided.

Example json query (take requires orderBy in views):

{
    "action": "findMany",
    "modelName": "UserView",
    "query": {
        "arguments": {
            "take": "1"
        },
        "selection": {
            "$scalars": true
        }
    }
}
Source

pub fn unknown_argument( selection_path: Vec<&str>, argument_path: Vec<&str>, valid_argument_descriptions: Vec<ArgumentDescription<'_>>, ) -> Self

Creates an ValidationErrorKind::UnknownArgument kind of error, which happens when the arguments for a query are not congruent with those expressed in the schema

Example json query:

{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “foo”: “123” }, “selection”: { “$scalars”: true } } } Todo: add the given type to the meta

Source

pub fn unknown_input_field( selection_path: Vec<&str>, argument_path: Vec<&str>, input_type_description: InputTypeDescription, ) -> Self

Creates a ValidationErrorKind::UnknownInputField kind of error, which happens when the argument value for a query contains a field that does not exist in the schema for the input type.

TODO: how is this conceptually different from an unknown argument? This used to be a FieldNotFoundError (see old code), but the same FieldNotFoundError was used to denote what’s now an UnknownSelectionField.

Example json query:

{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “foo”: 2 } }, “selection”: { “$scalars”: true } } }

Source

pub fn unknown_selection_field( selection_path: Vec<&str>, output_type_description: OutputTypeDescription, ) -> Self

Creates an ValidationErrorKind::UnknownSelectionField kind of error, which happens when the selection of fields for a query contains a field that does not exist in the schema for the enclosing type

Example json query:

{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: { “notAField”: true } }

Source

pub fn selection_set_on_scalar( field_name: String, selection_path: Vec<&str>, ) -> Self

Creates an ValidationErrorKind::SelectionSetOnScalar kind of error, which happens when there is a nested selection block on a scalar field

Example json query:

{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: { “email”: { “selection”: { “id”: true } } } } }

Source

pub fn union(errors: Vec<ValidationError>) -> Self

Creates an error that is the union of different validation errors

Source

pub fn value_too_large( selection_path: Vec<&str>, argument_path: Vec<&str>, value: String, ) -> Self

Creates an ValidationErrorKind::ValueTooLarge kind of error, which happens when the value for a float or integer coming from the JS client is larger than what can fit in an i64 (2^64 - 1 = 18446744073709550000)

Example json query

{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “id”: 18446744073709550000 // too large } }, “selection”: { “$scalars”: true } } }

Trait Implementations§

Source§

impl Debug for ValidationError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ValidationError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ValidationError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ValidationError> for Error

Source§

fn from(err: ValidationError) -> Self

Converts to this type from the input type.
Source§

impl From<ValidationError> for KnownError

Source§

fn from(err: ValidationError) -> Self

Converts to this type from the input type.
Source§

impl Serialize for ValidationError

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more