Bug 1450986 - [RFE] Could the ovirtsdk4.Error improved ?
Summary: [RFE] Could the ovirtsdk4.Error improved ?
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-sdk-python
Classification: oVirt
Component: RFEs
Version: 4.1.3
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ovirt-4.1.3
: 4.1.4
Assignee: Ondra Machacek
QA Contact: Petr Kubica
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-05-15 13:57 UTC by Fabrice Bacchella
Modified: 2017-07-06 13:19 UTC (History)
7 users (show)

Fixed In Version: python-ovirt-engine-sdk4-4.1.4
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-07-06 13:19:09 UTC
oVirt Team: Infra
Embargoed:
rule-engine: ovirt-4.1+
lsvaty: testing_plan_complete-
mgoldboi: planning_ack+
mperina: devel_ack+
lsvaty: testing_ack+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 76921 0 sdk_4.1 MERGED Add Error.code 2020-08-26 05:59:42 UTC
oVirt gerrit 76923 0 master MERGED Add Error.fault 2020-08-26 05:59:41 UTC
oVirt gerrit 76935 0 sdk_4.1 MERGED Add Error.code 2020-08-26 05:59:42 UTC
oVirt gerrit 76936 0 sdk_4.1 MERGED Add Error.fault 2020-08-26 05:59:42 UTC

Description Fabrice Bacchella 2017-05-15 13:57:32 UTC
The ovirtsdk4.Error is a basic wrapping around an generic python exception. I did try introspection of it's content and sees nothing else than a raw string argument. For example:
args ('Fault reason is "Operation Failed". Fault detail is "[Cannot switch the following Hosts to Maintenance mode: XXX.\nOne or more running VMs are indicated as non-migratable. The non-migratable VMs are: XXX , XXX.]". HTTP response code is 409.',)

As I used the sdk in a bigger application I would like to have in this case 3 variables:
The fault reasons: "Operation Failed"
The fault detail: "[Cannot switch the following Hosts to Maintenance mode: XXX.\nOne or more running VMs are indicated as non-migratable. The non-migratable VMs are: XXX , XXX.]"
The error code : 409.

That should be easy, they are all part of the returned message:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<action>
    <async>true</async>
    <fault>
        <detail>[Cannot switch the following Hosts to Maintenance mode: XXX.
One or more running VMs are indicated as non-migratable. The non-migratable VMs are: XXX , XXX.]</detail>
        <reason>Operation Failed</reason>
    </fault>
    <reason>For upgrade</reason>
    <status>failed</status>
</action>

I can then build a custom message with the details I need. For example, I don't think the HTTP response code is generally useful, unless in debug mode.

What do you think of that ?

Comment 1 Fabrice Bacchella 2017-05-15 14:30:40 UTC
Another use case where a smart exception would be useful:

ovirtsdk4.Error: Error during SSO revoke server_error : UT000021: Session already invalidated

I can catch this exception and transform it as a warning or a notice if details can be used, instead of having to use a brittle regex.

Comment 2 Juan Hernández 2017-05-16 08:02:12 UTC
Yes, that can be useful. I'd suggest to add two properties: 'code' and 'fault'. The first should be an integer containing the HTTP response code. The second should be an instance of the 'Fault' type, containing the detail and reason. Both should be optional, as certain errors won't have an HTTP error code or a fault (timeout, for example).

Comment 3 Petr Kubica 2017-06-07 11:11:55 UTC
Verified in python-ovirt-engine-sdk4-4.1.4-1.el7ev.x86_64


Note You need to log in before you can comment on or make changes to this bug.