Skip to content

Instantly share code, notes, and snippets.

@noperator-zz
Created August 18, 2021 18:08
Show Gist options
  • Save noperator-zz/a58cb0bb870265d8b29bfb9b12a3805e to your computer and use it in GitHub Desktop.
Save noperator-zz/a58cb0bb870265d8b29bfb9b12a3805e to your computer and use it in GitHub Desktop.
rpc: Prefix output with 'error' if command error occurs
Index: src/server/tcl_server.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c
--- a/src/server/tcl_server.c (revision 53556fcded056aa62ffdc6bf0c97bff87d891dab)
+++ b/src/server/tcl_server.c (revision 68ca08d3330564db706a66c6de01c0ae5056fad5)
@@ -183,6 +183,8 @@
unsigned char in[256];
char *tc_line_new;
int tc_line_size_new;
+ int command_result;
+ char error_buf[32];
rlen = connection_read(connection, &in, sizeof(in));
if (rlen <= 0) {
@@ -241,8 +243,13 @@
#undef ESTR
} else {
tclc->tc_line[tclc->tc_lineoffset-1] = '\0';
- command_run_line(connection->cmd_ctx, tclc->tc_line);
+ command_result = command_run_line(connection->cmd_ctx, tclc->tc_line);
result = Jim_GetString(Jim_GetResult(interp), &reslen);
+ if (command_result != ERROR_OK) {
+ /* send an error message */
+ snprintf(error_buf, sizeof(error_buf), "error %i: ", command_result);
+ tcl_output(connection, error_buf, strlen(error_buf));
+ }
retval = tcl_output(connection, result, reslen);
if (retval != ERROR_OK)
return retval;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment