Commit baf2bc4
authored
[errors] Improve error handling by using
This pull request introduces significant improvements and error handling
enhancements for arithmetic operations in the `BigInt` and `BigUInt`
types. Key changes include the removal of the `raises` keyword from
function signatures, the addition of structured error handling using
custom error types, and improvements to the implementation of arithmetic
operations to ensure correctness and maintainability.
### Improved Error Handling
* Introduced custom error types such as `DeciMojoError`,
`OverflowError`, and `ZeroDivisionError` across the codebase for more
structured and descriptive error reporting. For example, division and
modulo operations now raise `ZeroDivisionError` when dividing by zero.
* Replaced generic error messages with detailed exceptions that include
contextual information such as the file, function, and previous error,
improving debugging and traceability.
### Update TOML parser
* Updated the TOML parser by allowing parsing CRLF TOML files.
### Enhancements to Arithmetic Operations
* Removed the `raises` keyword from all arithmetic function signatures
in `src/decimojo/bigint/arithmetics.mojo` and
`src/decimojo/biguint/arithmetics.mojo`. This simplifies the function
definitions while maintaining error handling through explicit
exceptions.
* Updated the `add_inplace`, `subtract`, and `multiply` functions in
`src/decimojo/bigint/arithmetics.mojo` to use helper functions like
`negative` and `subtract_inplace_no_check` for better clarity and
modularity.
### Updates to BigInt Struct Methods
* Updated operator overloading methods (e.g., `__add__`, `__sub__`,
`__mul__`) in `src/decimojo/bigint/bigint.mojo` to remove the `raises`
keyword and include structured error handling where applicable.
* Enhanced in-place operators like `__iadd__` and `__isub__` to directly
call the updated arithmetic functions, ensuring consistency with the new
error handling approach.
### Codebase-Wide Improvements
* Added `.gitattributes` configuration to enforce LF (Unix-style) line
endings for consistency across the project.
* Improved modularity by importing `DeciMojoError` in relevant files
such as `src/decimojo/bigint/bigint.mojo` and
`src/decimojo/biguint/arithmetics.mojo`.
These changes collectively improve the robustness, readability, and
maintainability of the codebase while introducing a more structured
approach to error handling for arithmetic operations.DeciMojoError type (#114)1 parent 8a17db2 commit baf2bc4
File tree
8 files changed
+835
-166
lines changed- src
- decimojo
- bigint
- biguint
- tomlmojo
8 files changed
+835
-166
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | | - | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
76 | 77 | | |
| 78 | + | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
105 | | - | |
| 108 | + | |
106 | 109 | | |
107 | 110 | | |
108 | 111 | | |
| |||
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
117 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
118 | 124 | | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
122 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
123 | 132 | | |
124 | 133 | | |
125 | 134 | | |
| |||
165 | 174 | | |
166 | 175 | | |
167 | 176 | | |
168 | | - | |
| 177 | + | |
169 | 178 | | |
170 | 179 | | |
171 | 180 | | |
| |||
197 | 206 | | |
198 | 207 | | |
199 | 208 | | |
200 | | - | |
201 | 209 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
207 | 214 | | |
208 | 215 | | |
209 | 216 | | |
210 | 217 | | |
211 | 218 | | |
| 219 | + | |
| 220 | + | |
212 | 221 | | |
213 | | - | |
214 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
215 | 237 | | |
216 | 238 | | |
217 | 239 | | |
218 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
219 | 254 | | |
220 | 255 | | |
221 | 256 | | |
| |||
231 | 266 | | |
232 | 267 | | |
233 | 268 | | |
234 | | - | |
| 269 | + | |
235 | 270 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
243 | 285 | | |
244 | 286 | | |
245 | 287 | | |
| |||
254 | 296 | | |
255 | 297 | | |
256 | 298 | | |
257 | | - | |
258 | 299 | | |
259 | | - | |
260 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
261 | 304 | | |
262 | | - | |
263 | | - | |
| 305 | + | |
264 | 306 | | |
265 | 307 | | |
266 | 308 | | |
267 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
268 | 323 | | |
269 | 324 | | |
270 | 325 | | |
271 | | - | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
272 | 340 | | |
273 | 341 | | |
274 | 342 | | |
| |||
284 | 352 | | |
285 | 353 | | |
286 | 354 | | |
287 | | - | |
| 355 | + | |
288 | 356 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
296 | 371 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
463 | 464 | | |
464 | 465 | | |
465 | 466 | | |
466 | | - | |
| 467 | + | |
467 | 468 | | |
468 | 469 | | |
469 | 470 | | |
470 | | - | |
| 471 | + | |
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
474 | | - | |
| 475 | + | |
475 | 476 | | |
476 | 477 | | |
477 | 478 | | |
478 | 479 | | |
479 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
480 | 491 | | |
481 | 492 | | |
482 | 493 | | |
483 | | - | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
484 | 505 | | |
485 | 506 | | |
486 | 507 | | |
| |||
493 | 514 | | |
494 | 515 | | |
495 | 516 | | |
496 | | - | |
| 517 | + | |
497 | 518 | | |
498 | 519 | | |
499 | 520 | | |
500 | | - | |
| 521 | + | |
501 | 522 | | |
502 | 523 | | |
503 | 524 | | |
504 | | - | |
| 525 | + | |
505 | 526 | | |
506 | 527 | | |
507 | 528 | | |
| |||
524 | 545 | | |
525 | 546 | | |
526 | 547 | | |
527 | | - | |
| 548 | + | |
528 | 549 | | |
529 | 550 | | |
530 | 551 | | |
531 | | - | |
| 552 | + | |
532 | 553 | | |
533 | 554 | | |
534 | 555 | | |
| |||
538 | 559 | | |
539 | 560 | | |
540 | 561 | | |
541 | | - | |
| 562 | + | |
542 | 563 | | |
543 | 564 | | |
544 | 565 | | |
545 | | - | |
| 566 | + | |
546 | 567 | | |
547 | 568 | | |
548 | 569 | | |
| |||
0 commit comments