summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-06-20 16:10:55 +0200
committerBastien Nocera <hadess@hadess.net>2022-06-20 16:15:43 +0200
commite4dc32648883e0459518d59a10d8d174afa5dae4 (patch)
tree6ec1c4cf3c7cbf952925d974a4535ad4f10bbcb3
parent28313b1d75676d6653c4ebff566d0425fe1053b4 (diff)
downloadtotem-pl-parser-e4dc32648883e0459518d59a10d8d174afa5dae4.tar.gz
plparser: Fix return value from cancelled calls
As per the API documentation, and the code when it still used g_simple_async_result_*, totem_pl_parser_parse_finish() should return a TotemPlParserResult of TOTEM_PL_PARSER_RESULT_CANCELLED when parsing is cancelled. But the port to GTask changed that, as all the errors caught during parsing would return -1 as the error code, which isn't a valid TotemPlParserResult value. As the only way for totem_pl_parser_parse_finish() to have a GError set is for the call to be cancelled, catch that and correct the return value. Fixes: 45664037 ("plparse: Port from GSimpleAsyncResult to GTask") Closes: #38
-rw-r--r--plparse/totem-pl-parser.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index b853cb7..e10d40e 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -2408,12 +2408,24 @@ TotemPlParserResult
totem_pl_parser_parse_finish (TotemPlParser *parser, GAsyncResult *async_result, GError **error)
{
GTask *task = G_TASK (async_result);
+ GError *local_error = NULL;
+ int ret;
g_return_val_if_fail (TOTEM_PL_IS_PARSER (parser), TOTEM_PL_PARSER_RESULT_UNHANDLED);
g_return_val_if_fail (g_task_is_valid (async_result, parser), TOTEM_PL_PARSER_RESULT_UNHANDLED);
/* Propagate any errors which were caught and return the result; otherwise just return the result */
- return g_task_propagate_int (task, error);
+ ret = g_task_propagate_int (task, &local_error);
+ if (ret == -1) {
+ if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ ret = TOTEM_PL_PARSER_RESULT_CANCELLED;
+ g_error_free (local_error);
+ } else {
+ g_warning ("Unexpected error from asynchronous parsing: %s", local_error->message);
+ g_propagate_error (error, local_error);
+ }
+ }
+ return ret;
}
/**