@@ -314,6 +314,75 @@ RCUTILS_PUBLIC
314
314
void
315
315
rcutils_reset_error (void );
316
316
317
+ /// Set the error message using RCUTILS_SET_ERROR_MSG and append the previous error.
318
+ /**
319
+ * If there is no previous error, has same behavior as RCUTILS_SET_ERROR_MSG.
320
+ * \param[in] msg The error message to be set.
321
+ */
322
+ #define RCUTILS_SET_ERROR_MSG_AND_APPEND_PREV_ERROR (msg ) \
323
+ do { \
324
+ rcutils_error_string_t error_string = rcutils_get_error_string(); \
325
+ rcutils_reset_error(); \
326
+ RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING( \
327
+ RCUTILS_EXPAND(msg ": %s"), error_string.str); \
328
+ } while (0)
329
+
330
+ /// Set the error message with RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING and append the previous
331
+ /// error.
332
+ /**
333
+ * This function sets the error message using the given format string, and appends and resets the
334
+ * latest error string.
335
+ * The resulting formatted string is silently truncated at RCUTILS_ERROR_MESSAGE_MAX_LENGTH.
336
+ *
337
+ * If there is no previous error, has same behavior as RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING.
338
+ *
339
+ * \param[in] format_string The string to be used as the format of the error message.
340
+ * \param[in] ... Arguments for the format string.
341
+ */
342
+ #define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING_AND_APPEND_PREV_ERROR (format_string , ...) \
343
+ do { \
344
+ rcutils_error_string_t error_string = rcutils_get_error_string(); \
345
+ rcutils_reset_error(); \
346
+ RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING( \
347
+ RCUTILS_EXPAND(format_string ": %s"), __VA_ARGS__, error_string.str); \
348
+ } while (0)
349
+
350
+ /// Write the given msg out to stderr, limiting the buffer size in the `fwrite`, appending the
351
+ /// previous error.
352
+ /**
353
+ * This will reset the previous error, if it exists.
354
+ * If there is no previous error, has same behavior as RCUTILS_SAFE_FWRITE_TO_STDERR.
355
+ */
356
+ #define RCUTILS_SAFE_FWRITE_TO_STDERR_AND_APPEND_PREV_ERROR (msg ) \
357
+ do { \
358
+ rcutils_error_string_t error_string = rcutils_get_error_string(); \
359
+ rcutils_reset_error(); \
360
+ RCUTILS_SAFE_FWRITE_TO_STDERR(msg); \
361
+ RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(": %s", error_string.str); \
362
+ } while (0)
363
+
364
+ /// Set the error message to stderr using a format string and format arguments, appending the
365
+ /// previous error.
366
+ /**
367
+ * This function sets the error message to stderr using the given format string, appending and
368
+ * resetting the previous error.
369
+ * The resulting formatted string is silently truncated at RCUTILS_ERROR_MESSAGE_MAX_LENGTH.
370
+ *
371
+ * This will reset the previous error, if it exists.
372
+ * If there is no previous error, has same behavior as
373
+ * RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING.
374
+ *
375
+ * \param[in] format_string The string to be used as the format of the error message.
376
+ * \param[in] ... Arguments for the format string.
377
+ */
378
+ #define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING_AND_APPEND_PREV_ERROR (format_string , ...) \
379
+ do { \
380
+ rcutils_error_string_t error_string = rcutils_get_error_string(); \
381
+ rcutils_reset_error(); \
382
+ RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(format_string, __VA_ARGS__); \
383
+ RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING(": %s", error_string.str); \
384
+ } while (0)
385
+
317
386
#ifdef __cplusplus
318
387
}
319
388
#endif
0 commit comments