Commit f515e9d
## Motivation
This PR attempts to solve #1630 by introducing `err(Debug)` meta to
`intrument` attribute macro. As `err` meta causes the error (`e`)
returned by instrumented function to be passed to `tracing::error!(error
= %e)` i.e. makes it use the `Display` implementation of `e`, the newly
added `err(Debug)` makes expands to `tracing::error!(error = ?e)` which
makes the `error!` macro to use `Debug` implementation for `e`. `err`
and `err(Debug)` are mutually exclusive, adding both will create a
compilation error.
`err(Display)` is also supported to specify `Display` explicitly.
As tried to describe, for some types implementing `Error` it might be
more suitable to use `Debug` implementation as in the case of
`eyre::Result`. This frees us to manually go over the error chain and
print them all, so that `instrument` attribute macro would do it for us.
## Solution
- Added a custom keyword `err(Debug)` similar to `err`,
- Add `err(Debug)` field to `InstrumentArgs`,
- Add parsing for `err(Debug)` arg and check for conflicts with `err`,
- Generate `tracing::error!(error = ?e)` when `err(Debug)` is `true` and
`tracing::error!(error = %e)` when `err(Display)` or `err` is `true`,
- Interpolate generated `err_block` into `Err` branches in both async
and sync return positions, if `err` or `err(Debug)` is `true`.
1 parent 00aebfa commit f515e9d
2 files changed
+114
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
| 377 | + | |
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
387 | 399 | | |
388 | 400 | | |
389 | 401 | | |
| |||
591 | 603 | | |
592 | 604 | | |
593 | 605 | | |
594 | | - | |
595 | | - | |
596 | 606 | | |
597 | 607 | | |
598 | 608 | | |
| |||
705 | 715 | | |
706 | 716 | | |
707 | 717 | | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
708 | 724 | | |
709 | 725 | | |
710 | 726 | | |
711 | 727 | | |
712 | 728 | | |
713 | 729 | | |
714 | | - | |
715 | | - | |
| 730 | + | |
| 731 | + | |
716 | 732 | | |
717 | 733 | | |
718 | 734 | | |
719 | 735 | | |
720 | 736 | | |
721 | | - | |
| 737 | + | |
722 | 738 | | |
723 | 739 | | |
724 | 740 | | |
725 | 741 | | |
726 | | - | |
727 | | - | |
728 | | - | |
| 742 | + | |
| 743 | + | |
729 | 744 | | |
730 | | - | |
| 745 | + | |
731 | 746 | | |
732 | 747 | | |
733 | 748 | | |
| |||
764 | 779 | | |
765 | 780 | | |
766 | 781 | | |
767 | | - | |
| 782 | + | |
768 | 783 | | |
769 | 784 | | |
770 | 785 | | |
771 | 786 | | |
772 | 787 | | |
773 | 788 | | |
774 | 789 | | |
775 | | - | |
| 790 | + | |
776 | 791 | | |
777 | 792 | | |
778 | 793 | | |
| |||
802 | 817 | | |
803 | 818 | | |
804 | 819 | | |
805 | | - | |
| 820 | + | |
806 | 821 | | |
807 | 822 | | |
808 | 823 | | |
| |||
939 | 954 | | |
940 | 955 | | |
941 | 956 | | |
942 | | - | |
943 | | - | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
944 | 960 | | |
945 | 961 | | |
946 | 962 | | |
| |||
998 | 1014 | | |
999 | 1015 | | |
1000 | 1016 | | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
1001 | 1050 | | |
1002 | 1051 | | |
1003 | 1052 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
0 commit comments