[GH-ISSUE #172] proxmoxer doesn't distinguish between error types #92

Closed
opened 2026-02-27 15:46:22 +03:00 by kerem · 2 comments
Owner

Originally created by @kaysond on GitHub (Aug 27, 2024).
Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/172

Originally assigned to: @kaysond on GitHub.

Hi. I'd like to use proxmoxer for an ansible collection I'm writing that implements all of the PVE API paths. Ansible modules (generally) get run on the target host, which means using the local backend and the pvesh.

The problem I'm running into is that when pvesh returns non-zero, proxmoxer throws a proxmoxer.core.ResourceException with a 500 Internal Server Error regardless of the pvesh error code. pvesh itself, though, distinguishes between different error types. For example, it returns 1 if there is no handler defined for a given API path (e.g. if the path doesn't exist), but it returns 2 if the handler exists, but the parameter doesn't. See below for an example.

This is an important distinction for something like ansible because the parameter not existing isn't necessarily an error. It could be that we want to check if it exists before creating/updating. But if the API path is wrong, or some other issue occurs, we'd want the module to also throw an error.

I don't really want to parse the exception text in my module, so I'm hoping you'd be open to addressing this in the library. Happy to contribute the fix.

>>> p.get("/access/domains/pve")
{'comment': 'Proxmox VE authentication server', 'digest': 'da39a3ee5e6b4b0d3255bfef95601890afd80709', 'type': 'pve'}

>>> p.get("/access/domains/pvse")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 167, in get
    return self(args)._request("GET", params=params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 156, in _request
    raise ResourceException(
proxmoxer.core.ResourceException: 500 Internal Server Error: domain 'pvse' does not exist

>>> p.get("/access/domaisns/pve")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 167, in get
    return self(args)._request("GET", params=params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 156, in _request
    raise ResourceException(
proxmoxer.core.ResourceException: 500 Internal Server Error: No 'get' handler defined for '/access/domaisns/pve'
Originally created by @kaysond on GitHub (Aug 27, 2024). Original GitHub issue: https://github.com/proxmoxer/proxmoxer/issues/172 Originally assigned to: @kaysond on GitHub. Hi. I'd like to use proxmoxer for an ansible collection I'm writing that implements all of the PVE API paths. Ansible modules (generally) get run on the target host, which means using the local backend and the pvesh. The problem I'm running into is that when pvesh returns non-zero, proxmoxer throws a `proxmoxer.core.ResourceException` with a `500 Internal Server Error` regardless of the pvesh error code. pvesh itself, though, distinguishes between different error types. For example, it returns 1 if there is no handler defined for a given API path (e.g. if the path doesn't exist), but it returns 2 if the handler exists, but the parameter doesn't. See below for an example. This is an important distinction for something like ansible because the parameter not existing isn't necessarily an error. It could be that we want to check if it exists before creating/updating. But if the API path is wrong, or some other issue occurs, we'd want the module to also throw an error. I don't really want to parse the exception text in my module, so I'm hoping you'd be open to addressing this in the library. Happy to contribute the fix. ```python >>> p.get("/access/domains/pve") {'comment': 'Proxmox VE authentication server', 'digest': 'da39a3ee5e6b4b0d3255bfef95601890afd80709', 'type': 'pve'} >>> p.get("/access/domains/pvse") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 167, in get return self(args)._request("GET", params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 156, in _request raise ResourceException( proxmoxer.core.ResourceException: 500 Internal Server Error: domain 'pvse' does not exist >>> p.get("/access/domaisns/pve") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 167, in get return self(args)._request("GET", params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.venv/lib/python3.11/site-packages/proxmoxer/core.py", line 156, in _request raise ResourceException( proxmoxer.core.ResourceException: 500 Internal Server Error: No 'get' handler defined for '/access/domaisns/pve' ```
Author
Owner

@jhollowe commented on GitHub (Aug 29, 2024):

If pulling a field off the ResourceException object would work for you, this should be doable. I think it would be cleaner to change the existing field(s) on the exception object to contain the exit code of the *sh program, but that would break anything expecting the existing error messages.

I would add a new field to the ResourceException for the exit code, something like exit_code which is always 0 for HTTPS and is the exit code of the command for SSH/local.

<!-- gh-comment-id:2316662476 --> @jhollowe commented on GitHub (Aug 29, 2024): If pulling a field off the ResourceException object would work for you, this should be doable. I think it would be cleaner to change the existing field(s) on the exception object to contain the exit code of the `*sh` program, but that would break anything expecting the existing error messages. I would add a new field to the ResourceException for the exit code, something like `exit_code` which is always `0` for HTTPS and is the exit code of the command for SSH/local.
Author
Owner

@kaysond commented on GitHub (Aug 29, 2024):

Yeah I think a new field on the exception would be totally fine. I just discovered a separate problem, though, and that is that the error code doesn't seem to be consistent. I asked about it here: https://forum.proxmox.com/threads/pvesh-exit-codes-are-not-consistent.153582/

<!-- gh-comment-id:2316761569 --> @kaysond commented on GitHub (Aug 29, 2024): Yeah I think a new field on the exception would be totally fine. I just discovered a separate problem, though, and that is that the error code doesn't seem to be consistent. I asked about it here: https://forum.proxmox.com/threads/pvesh-exit-codes-are-not-consistent.153582/
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmoxer#92
No description provided.