diff mbox series

[v2,6/6] qga: Improve error report by calling error_setg_win32()

Message ID 20200227163101.414-7-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series misc: Improve error reporting on Windows | expand

Commit Message

Philippe Mathieu-Daudé Feb. 27, 2020, 4:31 p.m. UTC
Use error_setg_win32() which adds a hint similar to strerror(errno)).

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 qga/channel-win32.c  | 3 ++-
 qga/commands-win32.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

Comments

Marc-André Lureau Feb. 27, 2020, 5:20 p.m. UTC | #1
Hi

On Thu, Feb 27, 2020 at 5:32 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Use error_setg_win32() which adds a hint similar to strerror(errno)).
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  qga/channel-win32.c  | 3 ++-
>  qga/commands-win32.c | 6 +++---
>  2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/qga/channel-win32.c b/qga/channel-win32.c
> index 774205e017..4f04868a76 100644
> --- a/qga/channel-win32.c
> +++ b/qga/channel-win32.c
> @@ -308,7 +308,8 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
>      }
>
>      if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
> -        g_critical("error setting timeout for com port: %lu",GetLastError());
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> +        g_critical("error setting timeout for com port: %s", emsg);
>          CloseHandle(c->handle);
>          return false;
>      }
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 2461fd19bf..8e1f32ea23 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -315,8 +315,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
>      }
>
>      if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
> -        slog("guest-shutdown failed: %lu", GetLastError());
> -        error_setg(errp, QERR_UNDEFINED_ERROR);
> +        error_setg_win32(errp, GetLastError(), "guest-shutdown failed");

did you drop the slog() intentionally?

>      }
>  }
>
> @@ -1319,7 +1318,8 @@ static DWORD WINAPI do_suspend(LPVOID opaque)
>      DWORD ret = 0;
>
>      if (!SetSuspendState(*mode == GUEST_SUSPEND_MODE_DISK, TRUE, TRUE)) {
> -        slog("failed to suspend guest, %lu", GetLastError());
> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
> +        slog("failed to suspend guest: %s", emsg);
>          ret = -1;
>      }
>      g_free(mode);
> --
> 2.21.1
>
Philippe Mathieu-Daudé Feb. 27, 2020, 5:34 p.m. UTC | #2
On 2/27/20 6:20 PM, Marc-André Lureau wrote:
> Hi
> 
> On Thu, Feb 27, 2020 at 5:32 PM Philippe Mathieu-Daudé
> <philmd@redhat.com> wrote:
>>
>> Use error_setg_win32() which adds a hint similar to strerror(errno)).
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>   qga/channel-win32.c  | 3 ++-
>>   qga/commands-win32.c | 6 +++---
>>   2 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/qga/channel-win32.c b/qga/channel-win32.c
>> index 774205e017..4f04868a76 100644
>> --- a/qga/channel-win32.c
>> +++ b/qga/channel-win32.c
>> @@ -308,7 +308,8 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
>>       }
>>
>>       if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
>> -        g_critical("error setting timeout for com port: %lu",GetLastError());
>> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
>> +        g_critical("error setting timeout for com port: %s", emsg);
>>           CloseHandle(c->handle);
>>           return false;
>>       }
>> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
>> index 2461fd19bf..8e1f32ea23 100644
>> --- a/qga/commands-win32.c
>> +++ b/qga/commands-win32.c
>> @@ -315,8 +315,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
>>       }
>>
>>       if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
>> -        slog("guest-shutdown failed: %lu", GetLastError());
>> -        error_setg(errp, QERR_UNDEFINED_ERROR);
>> +        error_setg_win32(errp, GetLastError(), "guest-shutdown failed");
> 
> did you drop the slog() intentionally?

Oops no :(

> 
>>       }
>>   }
>>
>> @@ -1319,7 +1318,8 @@ static DWORD WINAPI do_suspend(LPVOID opaque)
>>       DWORD ret = 0;
>>
>>       if (!SetSuspendState(*mode == GUEST_SUSPEND_MODE_DISK, TRUE, TRUE)) {
>> -        slog("failed to suspend guest, %lu", GetLastError());
>> +        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
>> +        slog("failed to suspend guest: %s", emsg);
>>           ret = -1;
>>       }
>>       g_free(mode);
>> --
>> 2.21.1
>>
>
diff mbox series

Patch

diff --git a/qga/channel-win32.c b/qga/channel-win32.c
index 774205e017..4f04868a76 100644
--- a/qga/channel-win32.c
+++ b/qga/channel-win32.c
@@ -308,7 +308,8 @@  static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
     }
 
     if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
-        g_critical("error setting timeout for com port: %lu",GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        g_critical("error setting timeout for com port: %s", emsg);
         CloseHandle(c->handle);
         return false;
     }
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 2461fd19bf..8e1f32ea23 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -315,8 +315,7 @@  void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
     }
 
     if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
-        slog("guest-shutdown failed: %lu", GetLastError());
-        error_setg(errp, QERR_UNDEFINED_ERROR);
+        error_setg_win32(errp, GetLastError(), "guest-shutdown failed");
     }
 }
 
@@ -1319,7 +1318,8 @@  static DWORD WINAPI do_suspend(LPVOID opaque)
     DWORD ret = 0;
 
     if (!SetSuspendState(*mode == GUEST_SUSPEND_MODE_DISK, TRUE, TRUE)) {
-        slog("failed to suspend guest, %lu", GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        slog("failed to suspend guest: %s", emsg);
         ret = -1;
     }
     g_free(mode);