mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
util: virerror: Introduce virGetLastError{Code,Domain} public APIs
Many places in the code call virGetLastError() just to check the
raised error code, or domain. However virGetLastError() can return
NULL, so the code has to check for that first. This patch therefore
introduces virGetLasError{Code,Domain} functions which always return a
valid error code or domain respectively, thus dropping the need to
perform any checks on the error object.
Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
1 parent
52d88d11db
commit
50e96bb2a1
3 files changed
+43
No files matched your search
@@ -344,6 +344,8 @@ void virResetLastError (void);
|
||||
void virResetError (virErrorPtr err);
|
||||
void virFreeError (virErrorPtr err);
|
||||
|
||||
int virGetLastErrorCode (void);
|
||||
int virGetLastErrorDomain (void);
|
||||
const char * virGetLastErrorMessage (void);
|
||||
|
||||
virErrorPtr virConnGetLastError (virConnectPtr conn);
|
||||
|
||||
@@ -792,4 +792,10 @@ LIBVIRT_4.4.0 {
|
||||
virConnectBaselineHypervisorCPU;
|
||||
} LIBVIRT_4.1.0;
|
||||
|
||||
LIBVIRT_4.5.0 {
|
||||
global:
|
||||
virGetLastErrorCode;
|
||||
virGetLastErrorDomain;
|
||||
} LIBVIRT_4.4.0;
|
||||
|
||||
# .... define new API here using predicted next version number ....
|
||||
@@ -271,6 +271,41 @@ virGetLastError(void)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virGetLastErrorCode:
|
||||
*
|
||||
* Get the most recent error code (enum virErrorNumber).
|
||||
*
|
||||
* Returns the most recent error code, or VIR_ERR_OK if none is set.
|
||||
*/
|
||||
int
|
||||
virGetLastErrorCode(void)
|
||||
{
|
||||
virErrorPtr err = virLastErrorObject();
|
||||
if (!err)
|
||||
return VIR_ERR_OK;
|
||||
return err->code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virGetLastErrorDomain:
|
||||
*
|
||||
* Get the most recent error domain (enum virErrorDomain).
|
||||
*
|
||||
* Returns a numerical value of the most recent error's origin, or VIR_FROM_NONE
|
||||
* if none is set.
|
||||
*/
|
||||
int
|
||||
virGetLastErrorDomain(void)
|
||||
{
|
||||
virErrorPtr err = virLastErrorObject();
|
||||
if (!err)
|
||||
return VIR_FROM_NONE;
|
||||
return err->domain;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virGetLastErrorMessage:
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user