diff --git a/serde_codegen/src/ser.rs b/serde_codegen/src/ser.rs index 53160416..0fc928af 100644 --- a/serde_codegen/src/ser.rs +++ b/serde_codegen/src/ser.rs @@ -255,8 +255,11 @@ fn serialize_variant( let variant_ident = variant.ident.clone(); let variant_name = variant.attrs.name().serialize_name(); + + let skipped_msg = format!("The enum variant {}::{} cannot be serialized", + type_ident, variant_ident); let skipped_err = quote! { - Err(_serde::ser::Error::invalid_value("The enum variant was skipped for serialization")) + Err(_serde::ser::Error::invalid_value(#skipped_msg)) }; if variant.attrs.skip_serializing() { diff --git a/testing/tests/test_ser.rs b/testing/tests/test_ser.rs index afc85070..3a5a5748 100644 --- a/testing/tests/test_ser.rs +++ b/testing/tests/test_ser.rs @@ -402,17 +402,17 @@ fn test_enum_skipped() { assert_ser_tokens_error( &Enum::SkippedUnit, &[], - Error::InvalidValue("The enum variant was skipped for serialization".to_owned())); + Error::InvalidValue("The enum variant Enum::SkippedUnit cannot be serialized".to_owned())); assert_ser_tokens_error( &Enum::SkippedOne(42), &[], - Error::InvalidValue("The enum variant was skipped for serialization".to_owned())); + Error::InvalidValue("The enum variant Enum::SkippedOne cannot be serialized".to_owned())); assert_ser_tokens_error( &Enum::SkippedSeq(1, 2), &[], - Error::InvalidValue("The enum variant was skipped for serialization".to_owned())); + Error::InvalidValue("The enum variant Enum::SkippedSeq cannot be serialized".to_owned())); assert_ser_tokens_error( &Enum::SkippedMap { _a: 1, _b: 2 }, &[], - Error::InvalidValue("The enum variant was skipped for serialization".to_owned())); + Error::InvalidValue("The enum variant Enum::SkippedMap cannot be serialized".to_owned())); }