[gnome-builder/wip/gtk4-port: 1670/1774] libide/foundry: add push_error api for run command
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1670/1774] libide/foundry: add push_error api for run command
- Date: Mon, 11 Jul 2022 22:31:53 +0000 (UTC)
commit 0df0b0c0c55ec280cb27625ae4689c3518802829
Author: Christian Hergert <chergert redhat com>
Date: Mon Jun 27 14:32:15 2022 -0700
libide/foundry: add push_error api for run command
This is convenience API so that if you don't need a handler but still want
to propagate an error, which will block the final creation of a launcher,
you can do so synchronously.
When flattening layers, the error will propagate and stop further creation
of the subprocess launcher.
src/libide/foundry/ide-run-context.c | 45 ++++++++++++++++++++++++++++++++++++
src/libide/foundry/ide-run-context.h | 3 +++
2 files changed, 48 insertions(+)
---
diff --git a/src/libide/foundry/ide-run-context.c b/src/libide/foundry/ide-run-context.c
index 58ed61ce3..9c47ce5d4 100644
--- a/src/libide/foundry/ide-run-context.c
+++ b/src/libide/foundry/ide-run-context.c
@@ -298,6 +298,51 @@ ide_run_context_push_host (IdeRunContext *self)
NULL);
}
+static gboolean
+ide_run_context_error_handler (IdeRunContext *self,
+ const char * const *argv,
+ const char * const *env,
+ const char *cwd,
+ IdeUnixFDMap *unix_fd_map,
+ gpointer user_data,
+ GError **error)
+{
+ const GError *local_error = user_data;
+
+ g_assert (IDE_IS_RUN_CONTEXT (self));
+ g_assert (IDE_IS_UNIX_FD_MAP (unix_fd_map));
+ g_assert (local_error != NULL);
+
+ if (error != NULL)
+ *error = g_error_copy (local_error);
+
+ return FALSE;
+}
+
+/**
+ * ide_run_context_push_error:
+ * @self: a #IdeRunContext
+ * @error: (transfer full) (in): a #GError
+ *
+ * Pushes a new layer that will always fail with @error.
+ *
+ * This is useful if you have an error when attempting to build
+ * a run command, but need it to deliver the error when attempting
+ * to create a subprocess launcher.
+ */
+void
+ide_run_context_push_error (IdeRunContext *self,
+ GError *error)
+{
+ g_return_if_fail (IDE_IS_RUN_CONTEXT (self));
+ g_return_if_fail (error != NULL);
+
+ ide_run_context_push (self,
+ ide_run_context_error_handler,
+ error,
+ (GDestroyNotify)g_error_free);
+}
+
static gboolean
next_variable (const char *str,
guint *cursor,
diff --git a/src/libide/foundry/ide-run-context.h b/src/libide/foundry/ide-run-context.h
index 9171f05f4..f34105114 100644
--- a/src/libide/foundry/ide-run-context.h
+++ b/src/libide/foundry/ide-run-context.h
@@ -56,6 +56,9 @@ void ide_run_context_push (IdeRunContext
gpointer handler_data,
GDestroyNotify handler_data_destroy);
IDE_AVAILABLE_IN_ALL
+void ide_run_context_push_error (IdeRunContext *self,
+ GError *error);
+IDE_AVAILABLE_IN_ALL
void ide_run_context_push_host (IdeRunContext *self);
IDE_AVAILABLE_IN_ALL
void ide_run_context_push_expansion (IdeRunContext *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]