Repository: Azure/WALinuxAgent
Pull request #2663 (2022-09-09 21:56:58)

update traceback.format_exception etype argument
<!-- DO NOT DELETE THIS TEMPLATE -->

## Description

`Changed in version 3.10: The etype parameter has been renamed to exc and is now positional-only.
`
That is breaking the `traceback.format_exception` call since we pass value as keyword argument.

In older versions the etype parameter is mandatory argument.  So, changing from keyword argument to positional argument should fix the problem in all 3. * Versions.

Issue # <!-- if any -->
<!--
Please add an informative description that covers that changes made by the pull request. 
This checklist is used to make sure that common issues in a pull request are addressed.
This will expedite the process of getting your pull request merged and avoid extra work on your part to fix issues discovered during the review process.
-->

---

### PR information
- [ ] The title of the PR is clear and informative.
- [ ] There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).
- [ ] If applicable, the PR references the bug/issue that it fixes in the description.
- [ ] New Unit tests were added for the changes made

### Quality of Code and Contribution Guidelines
- [ ] I have read the [contribution guidelines](https://github.com/Azure/WALinuxAgent/blob/master/.github/CONTRIBUTING.md).

codecov[bot]: # [Codecov](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) Report
> Merging [#2663](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) (afbaca9) into [develop](https://codecov.io/gh/Azure/WALinuxAgent/commit/51b27a10ef841d0566a1eca1d965732380b123f9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) (51b27a1) will **decrease** coverage by `0.00%`.
> The diff coverage is `100.00%`.

```diff
@@             Coverage Diff             @@
##           develop    #2663      +/-   ##
===========================================
- Coverage    71.97%   71.96%   -0.01%     
===========================================
  Files          103      103              
  Lines        15688    15679       -9     
  Branches      2485     2486       +1     
===========================================
- Hits         11291    11283       -8     
+ Misses        3881     3879       -2     
- Partials       516      517       +1     
```


| [Impacted Files](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/utils/textutil.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi91dGlscy90ZXh0dXRpbC5weQ==) | `62.50% <100.00%> (ø)` | |
| [azurelinuxagent/common/protocol/goal\_state.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9wcm90b2NvbC9nb2FsX3N0YXRlLnB5) | `94.58% <0.00%> (-0.74%)` | :arrow_down: |
| [azurelinuxagent/common/protocol/wire.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9wcm90b2NvbC93aXJlLnB5) | `77.83% <0.00%> (-0.71%)` | :arrow_down: |
| [azurelinuxagent/common/protocol/hostplugin.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi9wcm90b2NvbC9ob3N0cGx1Z2luLnB5) | `87.23% <0.00%> (-0.44%)` | :arrow_down: |
| [azurelinuxagent/ga/update.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2dhL3VwZGF0ZS5weQ==) | `89.34% <0.00%> (ø)` | |
| [azurelinuxagent/ga/exthandlers.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2dhL2V4dGhhbmRsZXJzLnB5) | `85.70% <0.00%> (+0.01%)` | :arrow_up: |
| [azurelinuxagent/common/utils/archive.py](https://codecov.io/gh/Azure/WALinuxAgent/pull/2663/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi91dGlscy9hcmNoaXZlLnB5) | `81.92% <0.00%> (+0.20%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure)


Patch:
diff --git a/azurelinuxagent/common/utils/textutil.py b/azurelinuxagent/common/utils/textutil.py
index 153eb806..1ff7a7e9 100644
--- a/azurelinuxagent/common/utils/textutil.py
+++ b/azurelinuxagent/common/utils/textutil.py
@@ -445,7 +445,7 @@ def format_exception(exception):
     if tb is None or (sys.version_info[0] == 2 and e != exception):
         msg += "[Traceback not available]"
     else:
-        msg += ''.join(traceback.format_exception(etype=type(exception), value=exception, tb=tb))
+        msg += ''.join(traceback.format_exception(type(exception), value=exception, tb=tb))
 
     return msg
 


Test patch:
diff --git a/tests/utils/test_text_util.py b/tests/utils/test_text_util.py
index 3b29f936..ff129c40 100644
--- a/tests/utils/test_text_util.py
+++ b/tests/utils/test_text_util.py
@@ -206,6 +206,26 @@ class TestTextUtil(AgentTestCase):
         self.assertRaises(ValueError, textutil.format_memory_value, 'KiloBytes', 1)
         self.assertRaises(TypeError, textutil.format_memory_value, 'bytes', None)
 
+    def test_format_exception(self):
+        """
+        Test formatting of exception into human-readable format
+        """
+
+        def raise_exception(count=3):
+            if count <= 1:
+                raise Exception("Test Exception")
+            raise_exception(count - 1)
+
+        msg = ""
+        try:
+            raise_exception()
+        except Exception as e:
+            msg = textutil.format_exception(e)
+
+        self.assertIn("Test Exception", msg)
+        # Raise exception at count 1 after two nested calls since count starts at 3
+        self.assertEqual(2, msg.count("raise_exception(count - 1)"))
+
 
 if __name__ == '__main__':
     unittest.main()