@@ -129,12 +129,10 @@ pub enum ErrorType {
129
129
// ---------------------
130
130
// generic length errors - used for everything with a length except strings and bytes which need custom messages
131
131
TooShort {
132
- field_type : String ,
133
132
min_length : usize ,
134
133
actual_length : usize ,
135
134
} ,
136
135
TooLong {
137
- field_type : String ,
138
136
max_length : usize ,
139
137
actual_length : usize ,
140
138
} ,
@@ -414,14 +412,12 @@ impl ErrorType {
414
412
Self :: TooShort { .. } => extract_context ! (
415
413
TooShort ,
416
414
ctx,
417
- field_type: String ,
418
415
min_length: usize ,
419
416
actual_length: usize
420
417
) ,
421
418
Self :: TooLong { .. } => extract_context ! (
422
419
TooLong ,
423
420
ctx,
424
- field_type: String ,
425
421
max_length: usize ,
426
422
actual_length: usize
427
423
) ,
@@ -479,40 +475,44 @@ impl ErrorType {
479
475
480
476
pub fn message_template_python ( & self ) -> & ' static str {
481
477
match self {
482
- Self :: NoSuchAttribute { .. } => "Object has no attribute '{attribute}'" ,
483
- Self :: JsonInvalid { .. } => "Invalid JSON: {error}" ,
478
+ Self :: NoSuchAttribute { .. } => "Object has no attribute '{attribute}'" ,
479
+ Self :: JsonInvalid { .. } => "Invalid JSON: {error}" ,
484
480
Self :: JsonType => "JSON input should be string, bytes or bytearray" ,
485
481
Self :: RecursionLoop => "Recursion error - cyclic reference detected" ,
486
482
Self :: Missing => "Field required" ,
487
483
Self :: FrozenField => "Field is frozen" ,
488
484
Self :: FrozenInstance => "Instance is frozen" ,
489
485
Self :: ExtraForbidden => "Extra inputs are not permitted" ,
490
486
Self :: InvalidKey => "Keys should be strings" ,
491
- Self :: GetAttributeError { .. } => "Error extracting attribute: {error}" ,
492
- Self :: ModelType { .. } => "Input should be a valid dictionary or instance of {class_name}" ,
487
+ Self :: GetAttributeError { .. } => "Error extracting attribute: {error}" ,
488
+ Self :: ModelType { .. } => "Input should be a valid dictionary or instance of {class_name}" ,
493
489
Self :: ModelAttributesType => "Input should be a valid dictionary or object to extract fields from" ,
494
- Self :: DataclassType { .. } => "Input should be a dictionary or an instance of {class_name}" ,
495
- Self :: DataclassExactType { .. } => "Input should be an instance of {class_name}" ,
490
+ Self :: DataclassType { .. } => "Input should be a dictionary or an instance of {class_name}" ,
491
+ Self :: DataclassExactType { .. } => "Input should be an instance of {class_name}" ,
496
492
Self :: NoneRequired => "Input should be None" ,
497
- Self :: GreaterThan { .. } => "Input should be greater than {gt}" ,
498
- Self :: GreaterThanEqual { .. } => "Input should be greater than or equal to {ge}" ,
499
- Self :: LessThan { .. } => "Input should be less than {lt}" ,
500
- Self :: LessThanEqual { .. } => "Input should be less than or equal to {le}" ,
501
- Self :: MultipleOf { .. } => "Input should be a multiple of {multiple_of}" ,
493
+ Self :: GreaterThan { .. } => "Input should be greater than {gt}" ,
494
+ Self :: GreaterThanEqual { .. } => "Input should be greater than or equal to {ge}" ,
495
+ Self :: LessThan { .. } => "Input should be less than {lt}" ,
496
+ Self :: LessThanEqual { .. } => "Input should be less than or equal to {le}" ,
497
+ Self :: MultipleOf { .. } => "Input should be a multiple of {multiple_of}" ,
502
498
Self :: FiniteNumber => "Input should be a finite number" ,
503
- Self :: TooShort { ..} => "{field_type} should have at least {min_length} item{expected_plural} after validation, not {actual_length}" ,
504
- Self :: TooLong { ..} => "{field_type} should have at most {max_length} item{expected_plural} after validation, not {actual_length}" ,
499
+ Self :: TooShort { .. } => {
500
+ "Data should have at least {min_length} item{expected_plural} after validation, not {actual_length}"
501
+ }
502
+ Self :: TooLong { .. } => {
503
+ "Data should have at most {max_length} item{expected_plural} after validation, not {actual_length}"
504
+ }
505
505
Self :: IterableType => "Input should be iterable" ,
506
- Self :: IterationError { .. } => "Error iterating over object, error: {error}" ,
506
+ Self :: IterationError { .. } => "Error iterating over object, error: {error}" ,
507
507
Self :: StringType => "Input should be a valid string" ,
508
508
Self :: StringSubType => "Input should be a string, not an instance of a subclass of str" ,
509
509
Self :: StringUnicode => "Input should be a valid string, unable to parse raw data as a unicode string" ,
510
- Self :: StringTooShort { .. } => "String should have at least {min_length} characters" ,
511
- Self :: StringTooLong { .. } => "String should have at most {max_length} characters" ,
512
- Self :: StringPatternMismatch { .. } => "String should match pattern '{pattern}'" ,
513
- Self :: Enum { .. } => "Input should be {expected}" ,
510
+ Self :: StringTooShort { .. } => "String should have at least {min_length} characters" ,
511
+ Self :: StringTooLong { .. } => "String should have at most {max_length} characters" ,
512
+ Self :: StringPatternMismatch { .. } => "String should match pattern '{pattern}'" ,
513
+ Self :: Enum { .. } => "Input should be {expected}" ,
514
514
Self :: DictType => "Input should be a valid dictionary" ,
515
- Self :: MappingType { .. } => "Input should be a valid mapping, error: {error}" ,
515
+ Self :: MappingType { .. } => "Input should be a valid mapping, error: {error}" ,
516
516
Self :: ListType => "Input should be a valid list" ,
517
517
Self :: TupleType => "Input should be a valid tuple" ,
518
518
Self :: SetType => "Input should be a valid set" ,
@@ -525,36 +525,38 @@ impl ErrorType {
525
525
Self :: FloatType => "Input should be a valid number" ,
526
526
Self :: FloatParsing => "Input should be a valid number, unable to parse string as a number" ,
527
527
Self :: BytesType => "Input should be a valid bytes" ,
528
- Self :: BytesTooShort { .. } => "Data should have at least {min_length} bytes" ,
529
- Self :: BytesTooLong { .. } => "Data should have at most {max_length} bytes" ,
530
- Self :: ValueError { .. } => "Value error, {error}" ,
531
- Self :: AssertionError { .. } => "Assertion failed, {error}" ,
532
- Self :: CustomError { .. } => "" , // custom errors are handled separately
533
- Self :: LiteralError { .. } => "Input should be {expected}" ,
528
+ Self :: BytesTooShort { .. } => "Data should have at least {min_length} bytes" ,
529
+ Self :: BytesTooLong { .. } => "Data should have at most {max_length} bytes" ,
530
+ Self :: ValueError { .. } => "Value error, {error}" ,
531
+ Self :: AssertionError { .. } => "Assertion failed, {error}" ,
532
+ Self :: CustomError { .. } => "" , // custom errors are handled separately
533
+ Self :: LiteralError { .. } => "Input should be {expected}" ,
534
534
Self :: DateType => "Input should be a valid date" ,
535
- Self :: DateParsing { .. } => "Input should be a valid date in the format YYYY-MM-DD, {error}" ,
536
- Self :: DateFromDatetimeParsing { .. } => "Input should be a valid date or datetime, {error}" ,
535
+ Self :: DateParsing { .. } => "Input should be a valid date in the format YYYY-MM-DD, {error}" ,
536
+ Self :: DateFromDatetimeParsing { .. } => "Input should be a valid date or datetime, {error}" ,
537
537
Self :: DateFromDatetimeInexact => "Datetimes provided to dates should have zero time - e.g. be exact dates" ,
538
538
Self :: DatePast => "Date should be in the past" ,
539
539
Self :: DateFuture => "Date should be in the future" ,
540
540
Self :: TimeType => "Input should be a valid time" ,
541
- Self :: TimeParsing { .. } => "Input should be in a valid time format, {error}" ,
541
+ Self :: TimeParsing { .. } => "Input should be in a valid time format, {error}" ,
542
542
Self :: DatetimeType => "Input should be a valid datetime" ,
543
- Self :: DatetimeParsing { .. } => "Input should be a valid datetime, {error}" ,
544
- Self :: DatetimeObjectInvalid { .. } => "Invalid datetime object, got {error}" ,
543
+ Self :: DatetimeParsing { .. } => "Input should be a valid datetime, {error}" ,
544
+ Self :: DatetimeObjectInvalid { .. } => "Invalid datetime object, got {error}" ,
545
545
Self :: DatetimePast => "Input should be in the past" ,
546
546
Self :: DatetimeFuture => "Input should be in the future" ,
547
547
Self :: TimezoneNaive => "Input should not have timezone info" ,
548
548
Self :: TimezoneAware => "Input should have timezone info" ,
549
- Self :: TimezoneOffset { .. } => "Timezone offset of {tz_expected} required, got {tz_actual}" ,
549
+ Self :: TimezoneOffset { .. } => "Timezone offset of {tz_expected} required, got {tz_actual}" ,
550
550
Self :: TimeDeltaType => "Input should be a valid timedelta" ,
551
- Self :: TimeDeltaParsing { .. } => "Input should be a valid timedelta, {error}" ,
551
+ Self :: TimeDeltaParsing { .. } => "Input should be a valid timedelta, {error}" ,
552
552
Self :: FrozenSetType => "Input should be a valid frozenset" ,
553
- Self :: IsInstanceOf { .. } => "Input should be an instance of {class}" ,
554
- Self :: IsSubclassOf { .. } => "Input should be a subclass of {class}" ,
553
+ Self :: IsInstanceOf { .. } => "Input should be an instance of {class}" ,
554
+ Self :: IsSubclassOf { .. } => "Input should be a subclass of {class}" ,
555
555
Self :: CallableType => "Input should be callable" ,
556
- Self :: UnionTagInvalid { ..} => "Input tag '{tag}' found using {discriminator} does not match any of the expected tags: {expected_tags}" ,
557
- Self :: UnionTagNotFound { ..} => "Unable to extract tag using discriminator {discriminator}" ,
556
+ Self :: UnionTagInvalid { .. } => {
557
+ "Input tag '{tag}' found using {discriminator} does not match any of the expected tags: {expected_tags}"
558
+ }
559
+ Self :: UnionTagNotFound { .. } => "Unable to extract tag using discriminator {discriminator}" ,
558
560
Self :: ArgumentsType => "Arguments must be a tuple, list or a dictionary" ,
559
561
Self :: MissingArgument => "Missing required argument" ,
560
562
Self :: UnexpectedKeywordArgument => "Unexpected keyword argument" ,
@@ -563,14 +565,13 @@ impl ErrorType {
563
565
Self :: MissingPositionalOnlyArgument => "Missing required positional only argument" ,
564
566
Self :: MultipleArgumentValues => "Got multiple values for argument" ,
565
567
Self :: UrlType => "URL input should be a string or URL" ,
566
- Self :: UrlParsing { .. } => "Input should be a valid URL, {error}" ,
567
- Self :: UrlSyntaxViolation { .. } => "Input violated strict URL syntax rules, {error}" ,
568
- Self :: UrlTooLong { .. } => "URL should have at most {max_length} characters" ,
569
- Self :: UrlScheme { .. } => "URL scheme should be {expected_schemes}" ,
568
+ Self :: UrlParsing { .. } => "Input should be a valid URL, {error}" ,
569
+ Self :: UrlSyntaxViolation { .. } => "Input violated strict URL syntax rules, {error}" ,
570
+ Self :: UrlTooLong { .. } => "URL should have at most {max_length} characters" ,
571
+ Self :: UrlScheme { .. } => "URL scheme should be {expected_schemes}" ,
570
572
Self :: UuidType => "UUID input should be a string, bytes or UUID object" ,
571
573
Self :: UuidParsing { .. } => "Input should be a valid UUID, {error}" ,
572
- Self :: UuidVersion { .. } => "UUID version {expected_version} expected"
573
-
574
+ Self :: UuidVersion { .. } => "UUID version {expected_version} expected" ,
574
575
}
575
576
}
576
577
@@ -632,20 +633,18 @@ impl ErrorType {
632
633
Self :: LessThanEqual { le } => to_string_render ! ( tmpl, le) ,
633
634
Self :: MultipleOf { multiple_of } => to_string_render ! ( tmpl, multiple_of) ,
634
635
Self :: TooShort {
635
- field_type,
636
636
min_length,
637
637
actual_length,
638
638
} => {
639
639
let expected_plural = plural_s ( * min_length) ;
640
- to_string_render ! ( tmpl, field_type , min_length, actual_length, expected_plural)
640
+ to_string_render ! ( tmpl, min_length, actual_length, expected_plural)
641
641
}
642
642
Self :: TooLong {
643
- field_type,
644
643
max_length,
645
644
actual_length,
646
645
} => {
647
646
let expected_plural = plural_s ( * max_length) ;
648
- to_string_render ! ( tmpl, field_type , max_length, actual_length, expected_plural)
647
+ to_string_render ! ( tmpl, max_length, actual_length, expected_plural)
649
648
}
650
649
Self :: IterationError { error } => render ! ( tmpl, error) ,
651
650
Self :: StringTooShort { min_length } => to_string_render ! ( tmpl, min_length) ,
@@ -710,15 +709,13 @@ impl ErrorType {
710
709
Self :: LessThanEqual { le } => py_dict ! ( py, le) ,
711
710
Self :: MultipleOf { multiple_of } => py_dict ! ( py, multiple_of) ,
712
711
Self :: TooShort {
713
- field_type,
714
712
min_length,
715
713
actual_length,
716
- } => py_dict ! ( py, field_type , min_length, actual_length) ,
714
+ } => py_dict ! ( py, min_length, actual_length) ,
717
715
Self :: TooLong {
718
- field_type,
719
716
max_length,
720
717
actual_length,
721
- } => py_dict ! ( py, field_type , max_length, actual_length) ,
718
+ } => py_dict ! ( py, max_length, actual_length) ,
722
719
Self :: IterationError { error } => py_dict ! ( py, error) ,
723
720
Self :: StringTooShort { min_length } => py_dict ! ( py, min_length) ,
724
721
Self :: StringTooLong { max_length } => py_dict ! ( py, max_length) ,
0 commit comments