@@ -5,21 +5,16 @@ This library lets you define errors with a uniform set of attributes.
55Furthermore, the error message is implemented to be parseable,
66so that you can extract an error catalog from the code.
77
8- ## Attributes of Error Builder
8+ ## Creating an Error Object
99
10- Error messages are built in ` ExaError ` using the following predefined attributes.
11- All attributes of the error object except the error code are optional. Thus, the
12- ` ExaError ` will still work, even if the other attributes are not provided. Please
13- keep in mind that error-code should satisfy error-code format
14- (see [ error-code] ( #error-code ) ).
10+ Error objects are built using the function ` ExaError ` .
11+ Please keep in mind that error-code should satisfy the error-code format (see [ code] ( #code ) ).
1512
1613Flexibility is provided by introducing placeholder parameters to the error
17- message in two ways: (1) via the ` parameter ` attribute and (2) with positional
18- arguments. Furthermore, placeholders without parameters are filled with <null >.
14+ message.
1915
20- #### error-code
21- This attribute should be defined in the error message and provide the following
22- pattern (` ^[FEW]-[[A-Z][A-Z0-9]+(-[A-Z][A-Z0-9]+)*-[0-9]+$ ` ):
16+ #### code
17+ This parameter needs to obey the following format (` ^[FEW]-[[A-Z][A-Z0-9]+(-[A-Z][A-Z0-9]+)*-[0-9]+$ ` ):
2318
2419` severity "-" project-short-tag ["-" module-short-tag] "-" error-number ` where,
2520- _ severity_ : either F (Failure, not recoverable), or E (Error, recoverable),
@@ -34,120 +29,14 @@ Examples of valide error codes:
3429- F-VS-QRW-13
3530
3631#### message
37- This attribute includes error description which can be given by either a static
32+ This parameter includes the error description which can be given by either a static
3833string or a string containing placeholders in double curly brackets. Parameters
39- of placeholders in the error message can be given as positional arguments
40- as well as using the ` parameter ` attribute. The following two usages result in
41- the same message (` Error message with value ` ):
42- - ` .message("Error message with {{parameter}}", "value") `
43- - ` .message("Error message with {{parameter}}").parameter("parameter", "value") `
34+ of placeholders in the error message can be provided using the ` parameters ` parameter.
4435
45- Furthermore, multiple calls of the ` message ` method will append the corresponding
46- message to the previous ones.
47-
48- #### mitigation
49- This attribute provides a list of hints on how to fix the error. Its method
50- structure is the same as for the ` message ` attribute. Parameters of placeholders
51- in the mitigations can be given as positional arguments as well as using the
52- ` parameter ` attribute. Similar to the ` message ` method, multiple calls of
53- the ` mitigation ` method will append the corresponding mitigation to the
54- previous ones.
36+ #### mitigations
37+ This parameter provides a list of hints on how to fix the error.
38+ Parameters of placeholders in the mitigations can be given via the ` parameters ` parameter.
5539
56- Furthermore, if the only message we can give is to open a ticket, the
57- ` ticket mitigation() ` method can be called, which provides a predefined message
58- about it.
59-
60- #### parameter
61- This attribute takes the placeholder name and the parameter value
62- that will replace this placeholder as argument. It can be used for both message
63- and mitigations. For example usages, please see the
64- [ Parameters] ( #Parameters ) section.
65-
66- ## Usage
67-
68- ### Simple Messages
69- ``` python
70- ExaError.message_builder(" E-TEST-1" ).message(" Something went wrong." )
71- ```
72- The result of the error message:
73- ```
74- E-TEST-1: Something went wrong.
75- ```
76-
77-
78- ### Parameters
79- You can specify placeholders in the message and replace them with
80- parameters values.
81-
82- ``` python
83- ExaError.message_builder(" E-TEST-2" )
84- .message(" Unknown input: {{ input}} ." )
85- .parameter(" input" , " unknown" , " The illegal user input." )
86- ```
87- or inline:
88- ``` python
89- ExaError.message_builder(" E-TEST-2" )
90- .message(" Unknown input: {{ input}} ." , " unknown" )
91- ```
92- The result of both error messages is same:
93- ```
94- E-TEST-2: Unknown input: 'unknown'.
95- ```
96-
97- The optional third argument for ` parameter(name, value, description) `
98- method is used to generate a parameter description for the error-catalog.
99-
100- The builder automatically quotes parameters (depending on the type of the
101- parameter). If you don't want that, use the ` |uq ` suffix in the corresponding
102- placeholder, as follows:
103-
104- ``` python
105- ExaError.message_builder(" E-TEST-2" )
106- .message(" Unknown input: {{ input|uq}} ." )
107- .parameter(" input" , " unknown" , " The illegal user input." )
108- ```
109- The result of the error message:
110- ```
111- E-TEST-2: Unknown input: unknown.
112- ```
113-
114- ### Mitigations
115- The mitigations describe actions the user can take to resolve the error.
116- Here is an example of a mitigation definition:
117-
118- ``` python
119- ExaError.message_builder(" E-TEST-2" )
120- .message(" Not enough space on device." )
121- .mitigation(" Delete something." )
122- ```
123- The result of the error message:
124- ```
125- E-TEST-2: Not enough space on device. Delete something.
126- ```
127-
128- You can use parameters in mitigations too.
129- ``` python
130- ExaError.message_builder(" E-TEST-2" )
131- .message(" Not enough space on device {{ device}} ." )
132- .mitigation(" Delete something from {{ device}} ." )
133- .parameter(" device" , " /dev/sda1" , " name of the device" )
134- ```
135- The result of the error message:
136- ```
137- E-TEST-2: Not enough space on device '/dev/sda1'. Delete something from '/dev/sda1'.
138- ```
139-
140- You can chain ` mitigation ` definitions if you want to tell the users that there
141- is more than one solution, as follows:
142- ``` python
143- ExaError.message_builder(" E-TEST-2" )
144- .message(" Not enough space on device." )
145- .mitigation(" Delete something." )
146- .mitigation(" Create larger partition." )
147- ```
148- The result of the error message:
149- ```
150- E-TEST-2: Not enough space on device. Known mitigations:
151- * Delete something.
152- * Create larger partition.
153- ```
40+ #### parameters
41+ This argument takes a dictionary of placeholder names and the respective parameter values.
42+ They will be used to replace the placeholders in the mitigations and messages.
0 commit comments