On Sat, Jul 19, 2025 at 9:27 AM Markus Armbruster <arm...@redhat.com> wrote:

> Kostiantyn Kostiuk <kkost...@redhat.com> writes:
>
> > g_win32_error_message - translate a Win32 error code
> > (as returned by GetLastError()) into the corresponding message.
> >
> > In the same time, we call error_setg_win32_internal with
> > error codes from different Windows componets like VSS or
> > Performance monitor that provides different codes and
> > can't be converted with g_win32_error_message.
>
> Are these error codes from GetLastError()?
>

No.
VSS functions directly return an error code.
Section: Return value -
https://learn.microsoft.com/en-us/windows/win32/api/vsbackup/nf-vsbackup-ivssbackupcomponents-addtosnapshotset

Performance Counters API can return a system error code or a PDH error code.
Section: Return value -
https://learn.microsoft.com/en-us/windows/win32/api/pdh/nf-pdh-pdhopenqueryw
System error code = GetLastError, PDH error code, something else.

https://learn.microsoft.com/en-us/windows/win32/perfctrs/pdh-error-codes
FormatMessage requires LoadLibrary(L"pdh.dll") to work properly.


> >                                                In this
> > case, the empty suffix will be returned so error will be
> > masked.
> >
> > QGA error example:
> >  - before changes:
> >   {"error": {"class": "GenericError", "desc": "failed to add D:\\ to
> snapshot set: "}}
> >  - after changes:
> >   {"error": {"class": "GenericError", "desc": "failed to add D:\\ to
> snapshot set: unknown Windows error 0x8004230e"}}
>
> Exact reproducer?
>

Yes, for example, with VSS.
Execute: {"execute": "guest-fsfreeze-freeze-list", "arguments":
{"mountpoints": ["C:"]}}
After this commit, you will get {"error": {"class": "GenericError", "desc":
"failed to add C: to snapshot set: unknown Windows error 0x80042308"}}


>
> > Signed-off-by: Kostiantyn Kostiuk <kkost...@redhat.com>
> > ---
> >  util/error.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/util/error.c b/util/error.c
> > index daea2142f3..b1342558ae 100644
> > --- a/util/error.c
> > +++ b/util/error.c
> > @@ -188,6 +188,11 @@ void error_setg_win32_internal(Error **errp,
> >
> >      if (win32_err != 0) {
> >          suffix = g_win32_error_message(win32_err);
> > +        // g_win32_error_message() failed
> > +        if (!suffix[0]) {
> > +            g_free(suffix);
> > +            suffix = g_strdup_printf("unknown Windows error 0x%x",
> win32_err);
> > +        }
> >      }
> >
> >      va_start(ap, fmt);
>
>

Reply via email to