On Fri, Jan 26, 2024 at 01:38:05 -0800, Andrea Bolognani wrote:
On Fri, Jan 26, 2024 at 09:30:29AM +0100, Peter Krempa wrote:
> On Thu, Jan 25, 2024 at 09:06:54 -0800, Andrea Bolognani wrote:
> > I've never seen the 'raise Foo() from None' pattern though. Can
you
> > explain why it's needed here?
>
> Python would re-raise the original exception along with the new one
> without that.
I guess it doesn't hurt to have it there, but it doesn't seem very
useful either:
$ git diff
diff --git a/scripts/qemu-replies-tool.py b/scripts/qemu-replies-tool.py
index 9ab1c30ee2..bde6b2dad5 100755
--- a/scripts/qemu-replies-tool.py
+++ b/scripts/qemu-replies-tool.py
@@ -46,7 +46,7 @@ def qemu_replies_load(filename):
jsonstr = ''
except json.decoder.JSONDecodeError as je:
- raise qrtException("JSON error:\n'%s'\nwhile processing
snippet:\n'%s'" % (je, jsonstr)) from None
+ raise qrtException("JSON error:\n'%s'\nwhile processing
snippet:\n'%s'" % (je, jsonstr))
if command is not None or jsonstr != '':
if command is not None:
diff --git a/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.replies
b/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.replies
index cc2190dfd3..cf1425e0bb 100644
--- a/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.replies
+++ b/tests/qemucapabilitiesdata/caps_8.2.0_x86_64.replies
@@ -1,5 +1,5 @@
{
- "execute": "qmp_capabilities",
+ "execute": } "qmp_capabilities",
"id": "libvirt-1"
}
$ ./scripts/qemu-replies-tool.py
tests/qemucapabilitiesdata/caps_8.2.0_x86_64.replies
'tests/qemucapabilitiesdata/caps_8.2.0_x86_64.replies' ... FAIL
JSON error:
'Expecting value: line 2 column 14 (char 15)'
while processing snippet:
'{
"execute": } "qmp_capabilities",
"id": "libvirt-1"
}
'
The behavior without it is just the same AFAICT.
Interesting. I definitely saw two exceptions when I was developing the
script so some later change probably in catching the exception has
changed how it behaves.