Skip to content

Commit cde4d31

Browse files
handle IPC call errors and bubble them up
1 parent 6d7eefb commit cde4d31

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

bins/recipe-runner/src/runner.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ GglError runner(const RecipeRunnerArgs *args) {
542542
ggl_buffer_from_null_term(socket_path), &resp, &conn
543543
);
544544
if (ret != GGL_ERR_OK) {
545+
GGL_LOGE("Runner failed to authenticate with nucleus.");
545546
return ret;
546547
}
547548

@@ -577,6 +578,7 @@ GglError runner(const RecipeRunnerArgs *args) {
577578
&GGL_STR("aws.greengrass.NucleusLite"),
578579
&resp
579580
);
581+
580582
if (ret != GGL_ERR_OK) {
581583
GGL_LOGE("Failed to get region from config.");
582584
return ret;
@@ -605,7 +607,12 @@ GglError runner(const RecipeRunnerArgs *args) {
605607
&resp
606608
);
607609
switch (ret) {
610+
case GGL_ERR_NOMEM:
611+
GGL_LOGW("Failed to get network proxy url from config - lack of memory."
612+
);
613+
break;
608614
case GGL_ERR_NOENTRY:
615+
GGL_LOGW("Failed to get network proxy url - no such entry.");
609616
break;
610617
case GGL_ERR_OK: {
611618
resp.data[resp.len] = '\0';
@@ -619,7 +626,7 @@ GglError runner(const RecipeRunnerArgs *args) {
619626
}
620627
default:
621628
GGL_LOGE("Failed to get proxy url from config.");
622-
return ret;
629+
break;
623630
}
624631

625632
resp = GGL_BUF(resp_mem);
@@ -631,7 +638,12 @@ GglError runner(const RecipeRunnerArgs *args) {
631638
&resp
632639
);
633640
switch (ret) {
641+
case GGL_ERR_NOMEM:
642+
GGL_LOGW("Failed to get noProxyAddresses from config - lack of memory."
643+
);
644+
break;
634645
case GGL_ERR_NOENTRY:
646+
GGL_LOGW("Failed to get noProxyAddresses - no such entry.");
635647
break;
636648
case GGL_ERR_OK: {
637649
resp.data[resp.len] = '\0';
@@ -641,7 +653,7 @@ GglError runner(const RecipeRunnerArgs *args) {
641653
}
642654
default:
643655
GGL_LOGE("Failed to get noProxyAddresses from config.");
644-
return ret;
656+
break;
645657
}
646658

647659
static uint8_t thing_name_mem[MAX_THING_NAME_LEN + 1];

modules/ggipc-client/src/client.c

+40-21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <ggl/object.h>
2525
#include <ggl/socket.h>
2626
#include <ggl/vector.h>
27+
#include <inttypes.h>
2728
#include <limits.h>
2829
#include <pthread.h>
2930
#include <string.h>
@@ -64,9 +65,7 @@ static GglError get_message(
6465
int conn,
6566
GglBuffer recv_buffer,
6667
EventStreamMessage *msg,
67-
EventStreamCommonHeaders *common_headers,
68-
GglAlloc *alloc,
69-
GglObject *payload
68+
EventStreamCommonHeaders *common_headers
7069
) {
7170
assert(msg != NULL);
7271

@@ -109,14 +108,6 @@ static GglError get_message(
109108
}
110109
}
111110

112-
if (payload != NULL) {
113-
ret = ggl_json_decode_destructive(msg->payload, alloc, payload);
114-
if (ret != GGL_ERR_OK) {
115-
return ret;
116-
}
117-
msg->payload.len = 0;
118-
}
119-
120111
return GGL_ERR_OK;
121112
}
122113

@@ -150,7 +141,8 @@ GglError ggipc_connect_auth(GglBuffer socket_path, GglBuffer *svcuid, int *fd) {
150141
EventStreamMessage msg = { 0 };
151142
EventStreamCommonHeaders common_headers;
152143

153-
ret = get_message(conn, recv_buffer, &msg, &common_headers, NULL, NULL);
144+
ret = get_message(conn, recv_buffer, &msg, &common_headers);
145+
154146
if (ret != GGL_ERR_OK) {
155147
return ret;
156148
}
@@ -165,6 +157,10 @@ GglError ggipc_connect_auth(GglBuffer socket_path, GglBuffer *svcuid, int *fd) {
165157
return GGL_ERR_FAILURE;
166158
}
167159

160+
if (msg.payload.len != 0) {
161+
GGL_LOGW("Eventstream connection ack has unexpected payload.");
162+
}
163+
168164
EventStreamHeaderIter iter = msg.headers;
169165
EventStreamHeader header;
170166

@@ -222,6 +218,7 @@ GglError ggipc_call(
222218

223219
GglError ret = send_message(conn, headers, headers_len, &params);
224220
if (ret != GGL_ERR_OK) {
221+
GGL_LOGE("Failed to send message %d", ret);
225222
return ret;
226223
}
227224

@@ -231,28 +228,50 @@ GglError ggipc_call(
231228
EventStreamMessage msg = { 0 };
232229
EventStreamCommonHeaders common_headers;
233230

234-
ret = get_message(conn, recv_buffer, &msg, &common_headers, alloc, result);
231+
ret = get_message(conn, recv_buffer, &msg, &common_headers);
235232
if (ret != GGL_ERR_OK) {
233+
GGL_LOGE("get_message returned %d", ret);
236234
return ret;
237235
}
238236

239-
if (result != NULL) {
240-
ret = ggl_obj_buffer_copy(result, alloc);
241-
if (ret != GGL_ERR_OK) {
242-
return ret;
243-
}
244-
}
245-
246237
if (common_headers.stream_id != 1) {
247238
GGL_LOGE("Unknown stream id received.");
248239
return GGL_ERR_FAILURE;
249240
}
250241

242+
if (common_headers.message_type == EVENTSTREAM_APPLICATION_ERROR) {
243+
GGL_LOGI(
244+
"Received IPC error on stream %" PRId32 ". Payload: %.*s.",
245+
common_headers.stream_id,
246+
(int) msg.payload.len,
247+
msg.payload.data
248+
);
249+
return GGL_ERR_FAILURE;
250+
}
251+
251252
if (common_headers.message_type != EVENTSTREAM_APPLICATION_MESSAGE) {
252-
GGL_LOGE("Connection response not an ack.");
253+
GGL_LOGE(
254+
"Stream %" PRId32 " received invalid message type: %" PRId32 ".",
255+
common_headers.stream_id,
256+
common_headers.message_type
257+
);
253258
return GGL_ERR_FAILURE;
254259
}
255260

261+
if (result != NULL) {
262+
ret = ggl_json_decode_destructive(msg.payload, alloc, result);
263+
if (ret != GGL_ERR_OK) {
264+
GGL_LOGE("ggl_json_decode_destructive returned %d", ret);
265+
return ret;
266+
}
267+
268+
ret = ggl_obj_buffer_copy(result, alloc);
269+
if (ret != GGL_ERR_OK) {
270+
GGL_LOGE("Failed to copy buffer %d", ret);
271+
return ret;
272+
}
273+
}
274+
256275
return GGL_ERR_OK;
257276
}
258277

0 commit comments

Comments
 (0)