serialization: intro `AttributeMissingError`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 24 Jul 2017 14:07:56 +0000 (10:07 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 26 Jul 2017 15:03:45 +0000 (11:03 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/serialization/serialization.nit

index d03f77d..0530579 100644 (file)
@@ -169,17 +169,22 @@ abstract class Deserializer
        var errors = new Array[Error]
 end
 
-# Error on invalid dynamic type for a deserialized attribute
-class AttributeTypeError
+# Deserialization error related to an attribute of `receiver`
+abstract class AttributeError
        super Error
 
-       autoinit receiver, attribute_name, attribute, expected_type
-
        # Parent object of the problematic attribute
        var receiver: Object
 
        # Name of the problematic attribute in `receiver`
        var attribute_name: String
+end
+
+# Invalid dynamic type for a deserialized attribute
+class AttributeTypeError
+       super AttributeError
+
+       autoinit receiver, attribute_name, attribute, expected_type
 
        # Deserialized object that isn't of the `expected_type`
        var attribute: nullable Object
@@ -196,6 +201,17 @@ class AttributeTypeError
        end
 end
 
+# Missing attribute at deserialization
+class AttributeMissingError
+       super AttributeError
+
+       autoinit receiver, attribute_name
+
+       redef var message is lazy do
+               return "Deserialization Error: Missing attribute `{receiver.class_name}::{attribute_name}`"
+       end
+end
+
 # Instances of this class can be passed to `Serializer::serialize`
 interface Serializable
        # Serialize `self` to `serializer`