@@ -402,11 +402,12 @@ class ResultErr(Exception):
402402
403403
404404 Attributes:
405- msg (list[str]): List of the error messages that have been added (does not have to match error_codes[code]).
406- code (list[int]): List of the error codes that have been added (does not have to match error_codes[msg]).
407- traceback_info (list[list[str]]): List of lists that contains the traceback information for each error message
408- size (int): Returns the number of error messages.
409- error (bool): Returns true if in error status (ie, size > 0).
405+ size (int): Returns the number of error messages.
406+ is_Ok (bool): Returns False if in error status (ie, size == 0).
407+ is_Err (bool): Returns True if in error status (ie, size > 0).
408+ Err_msg (list[str]): List of the error messages that have been added (does not have to match error_codes[code]).
409+ Err_traceback (list[list[str]]): List of lists that contains the traceback information for each error message
410+
410411
411412 Methods:
412413 raises(note=""):
@@ -495,6 +496,10 @@ def __init__(self, msg="", code=1, error_code_group=1, add_traceback=True, max_m
495496 error_code_group (int, optional): Identify the error_codes group to use for code and message flags.
496497 Default is 1. Error codes are stored as a class variable,
497498 so this is useful if you need different sets of error codes within a program.
499+ add_traceback (bool, optional): If True, then code traceback information is added to the message.
500+ max_messages (int, optional): The maximum number of error messages to store.
501+ After this, all additional messages are ignored.
502+ Default is 20.
498503 """
499504 super ().__init__ ()
500505 self .max_messages = max_messages if max_messages > 1 else 1
@@ -617,20 +622,23 @@ def error_code_description(self, description=None, error_code_group=None):
617622 return self .__class__ ._error_codes [g ]
618623 return self .__class__ ._error_codes [g ][description ]
619624
620- def raises (self , error_msg = "" ):
625+ def raises (self , add_traceback = False , error_msg = "" ):
621626 """
622627 Raise a ResultErr exception if there are error messages.
623628
624629 Args:
625- error_msg (str): Optional note to append to the error.
630+ add_traceback (bool): Optional, add traceback info at raises call.
631+ error_msg (str): Optional note to append to the error.
626632 """
627633 if len (self .msg ) > 0 :
628634 if error_msg != "" :
629- self .append (str (error_msg ), add_traceback = False )
635+ self .append (str (error_msg ), add_traceback = add_traceback )
636+ elif add_traceback :
637+ self .append ("ResultErr.raises Exception" )
630638 raise self
631639
632640 def expect (self , error_msg = "" ):
633- self .raises (error_msg )
641+ self .raises (True , error_msg )
634642 return self
635643
636644 def unwrap (self ):
@@ -667,10 +675,11 @@ def clear(self):
667675 """Clear all stored error messages and reset the instance to non-error status."""
668676 self .msg .clear ()
669677 self .code .clear ()
678+ self .traceback_info .clear ()
670679
671680 def pop (self ):
672681 """Remove and return the last stored error message and its code."""
673- return self .code .pop (), self .msg .pop ()
682+ return self .code .pop (), self .msg .pop (), self . traceback_info . pop ()
674683
675684 def has_msg (self , msg ):
676685 """Check if a specific message exists in the error messages."""
@@ -848,9 +857,14 @@ class Result:
848857
849858 Ok (any):
850859 If Ok variant, then returns value in Ok(value);
851- If Err variant, then raise Err and optionally append error_msg to it .
860+ If Err variant, then raises a ResultErr exception .
852861 Equivalent to the expect() method.
853862
863+ Err (any):
864+ If Ok variant, then raises a ResultErr exception;
865+ If Err variant, then returns the wrapped ResultErr.
866+ Equivalent to the expect_Err() method.
867+
854868 Err_msg (list[str]):
855869 For the Ok(value) variant, returns `[]`.
856870 For the Err(error) variant, returns list of error messages.
@@ -868,25 +882,25 @@ class Result:
868882
869883 Methods:
870884
885+ raises(add_traceback=False, error_msg="", error_code=1):
886+ If Ok variant, then returns Ok(value);
887+ If Err variant, then raises a ResultErr exception`.
888+ Useful for check during chained operations
889+
871890 unwrap():
872- Return the wrapped value in Ok(value) or error in Err(error ).
891+ Return the wrapped value in Ok(value) or e in Err(e ).
873892
874893 unwrap_or(default):
875894 Return the wrapped value in Ok(value) or return default.
876895
877896 expect(error_msg=""):
878- If Ok variant, then returns value in Ok(value);
879- If Err variant, then raise Err and optionally append error_msg to it.
897+ If Ok variant, then return the wrapped value in Ok(value);
898+ If Err variant, then raises a ResultErr exception and optionally append error_msg to it.
880899 Equivalent to the `Ok` attribute.
881900
882901 expect_Err(ok_msg=""):
883- If Ok variant, then raise ResultErr(ok_msg);
884- If Err variant, then returns error in Err(error), which is type ResultErr.
885-
886- raises(add_traceback=False, error_msg="", error_code=1):
887- If Ok variant, then returns Ok(value);
888- If Err variant, then raise Err and optionally include `from exception`.
889- Useful for check during chained operations
902+ If Ok variant, then raises ResultErr(ok_msg);
903+ If Err variant, then returns e in Err(e), which is type ResultErr.
890904
891905 is_Ok_and(bool_ok_func, *args, **kwargs):
892906 True if Ok(value) variant and ok_func(value, *args, **kwargs) returns True,
@@ -903,7 +917,7 @@ class Result:
903917 Maps a function to the Result to return a new Result.
904918 For the Ok(value) variant, returns `Ok(ok_func(value, *args, **kwargs))`.
905919 For the Err(error) variant, returns `Ok(default)`.
906- - If ok_func fails, returns `Result (default)`.
920+ - If ok_func fails, returns `Ok (default)`.
907921
908922 apply_or_else(err_func, ok_func, *args, **kwargs):
909923 Maps a function to the Result to return a new Result.
0 commit comments