@@ -380,3 +380,41 @@ def resolve_enum(enum_obj, value):
380
380
return enum_obj (value )
381
381
except ValueError :
382
382
return value
383
+
384
+
385
+ class KaitaiStructError (BaseException ):
386
+ """Common ancestor for all error originating from Kaitai Struct usage.
387
+ Stores KSY source path, pointing to an element supposedly guilty of
388
+ an error.
389
+ """
390
+ def __init__ (self , msg , src_path ):
391
+ super (KaitaiStructError , self ).__init__ ("%s: %s" % (src_path , msg ))
392
+ self .src_path = src_path
393
+
394
+
395
+ class UndecidedEndiannessError (KaitaiStructError ):
396
+ """Error that occurs when default endianness should be decided with
397
+ switch, but nothing matches (although using endianness expression
398
+ implies that there should be some positive result).
399
+ """
400
+ def __init__ (self , src_path ):
401
+ super (KaitaiStructError , self ).__init__ ("unable to decide on endianness for a type" , src_path )
402
+
403
+
404
+ class ValidationFailedError (KaitaiStructError ):
405
+ """Common ancestor for all validation failures. Stores pointer to
406
+ KaitaiStream IO object which was involved in an error.
407
+ """
408
+ def __init__ (self , msg , io , src_path ):
409
+ super (ValidationFailedError , self ).__init__ ("at pos %d: validation failed: %s" % (io .pos (), msg ), src_path )
410
+ self .io = io
411
+
412
+
413
+ class ValidationNotEqualError (ValidationFailedError ):
414
+ """Signals validation failure: we required "actual" value to be equal to
415
+ "expected", but it turned out that it's not.
416
+ """
417
+ def __init__ (self , expected , actual , io , src_path ):
418
+ super (ValidationNotEqualError , self ).__init__ ("not equal, expected %s, but got %s" % (repr (expected ), repr (actual )), io , src_path )
419
+ self .expected = expected
420
+ self .actual = actual
0 commit comments