Commit 7250a5d
committed
Improve BatteryManager error reporting
A `KeyError` was raised to indicate errors while getting inverters for
batteries, but this have a couple of issues.
First, the `KeyError` was converted to a string to get an error message,
but `KeyError` is a very special error, and the argument is interpreted
as a *key*, not as an error message, so when converting the error to a
`str`, the result is the `repr()` of the *key*, so the strings are
quoted and escaped, which is not what we want to report errors
downstream.
Second, one of the reported errors isn't really a `KeyError`, it is just
a mismatch between what is requested and the current microgrid topology,
so using a `KeyError` was completely wrong.
Since these errors were only used to report errors from a direct call,
we change `_get_components_data()` to return `list[InvBatPair] | str`,
where if there is an error, a `str` with the error description is
returned directly.
As an extra, we sort the IDs when used in error messages, so they are
easier to read for users, and more deterministic for tests.
Tests are also simplified to remove the use of regex, which were
probably only used because string were quoted.
Signed-off-by: Leandro Lucarella <[email protected]>1 parent 69b79a9 commit 7250a5d
File tree
2 files changed
+28
-29
lines changed- src/frequenz/sdk/microgrid/_power_distributing/_component_managers
- tests/microgrid/power_distributing
2 files changed
+28
-29
lines changedLines changed: 23 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | | - | |
237 | | - | |
| 237 | + | |
| 238 | + | |
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
| |||
510 | 511 | | |
511 | 512 | | |
512 | 513 | | |
513 | | - | |
| 514 | + | |
514 | 515 | | |
515 | 516 | | |
516 | 517 | | |
517 | 518 | | |
518 | 519 | | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | 520 | | |
523 | | - | |
| 521 | + | |
| 522 | + | |
524 | 523 | | |
| 524 | + | |
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | | - | |
| 533 | + | |
534 | 534 | | |
535 | | - | |
| 535 | + | |
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
548 | | - | |
549 | | - | |
550 | | - | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
551 | 552 | | |
552 | 553 | | |
553 | 554 | | |
| |||
556 | 557 | | |
557 | 558 | | |
558 | 559 | | |
559 | | - | |
| 560 | + | |
560 | 561 | | |
561 | 562 | | |
562 | 563 | | |
| |||
570 | 571 | | |
571 | 572 | | |
572 | 573 | | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
573 | 577 | | |
574 | 578 | | |
575 | 579 | | |
| |||
Lines changed: 5 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
474 | 473 | | |
475 | 474 | | |
476 | 475 | | |
477 | | - | |
| 476 | + | |
478 | 477 | | |
479 | 478 | | |
480 | 479 | | |
| |||
821 | 820 | | |
822 | 821 | | |
823 | 822 | | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
829 | 826 | | |
830 | | - | |
831 | 827 | | |
832 | 828 | | |
833 | 829 | | |
| |||
1054 | 1050 | | |
1055 | 1051 | | |
1056 | 1052 | | |
1057 | | - | |
1058 | | - | |
| 1053 | + | |
1059 | 1054 | | |
1060 | 1055 | | |
1061 | 1056 | | |
| |||
0 commit comments