2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 /* IWYU pragma: private, include <babeltrace2/babeltrace.h> */
9 #ifndef BABELTRACE2_ERROR_REPORTING_H
10 #define BABELTRACE2_ERROR_REPORTING_H
12 #ifndef __BT_IN_BABELTRACE_H
13 # error "Please include <babeltrace2/babeltrace.h> instead."
18 #include <babeltrace2/types.h>
19 #include <babeltrace2/graph/component-class.h>
26 @defgroup api-error Error reporting
29 Error reporting functions and macros.
31 This module contains functions and macros to report rich errors from a
32 user function (a \bt_comp_cls method, a
33 \ref api-qexec "query operation", or a trace processing \bt_graph
34 listener, for example) to any function caller.
36 Because \bt_name orchestrates pieces written by different authors,
37 it is important that an error which occurs deep into the function call
38 stack can percolate up to its callers.
40 The very basic mechanism to report an error from a function is to
41 \ref api-fund-func-status "return an error status"
42 (a status code enumerator which contains the word
43 \c ERROR): each function caller can clean its own context and return an
44 error status code itself until one caller "catches" the status code and
45 reacts to it. For example, the reaction can be to show an error message
48 This error reporting API adds a layer so that each function which
49 returns an error status code can append a message which describes the
50 cause of the error within the function's context.
52 Functions append error causes to the current thread's error. Having one
53 error object per thread makes this API thread-safe.
55 Here's a visual, step-by-step example:
57 @image html error-reporting-steps-1234.png
59 -# The trace processing \bt_graph user calls bt_graph_run().
61 -# bt_graph_run() calls the
62 \ref api-comp-cls-dev-meth-consume "consuming method" of the
65 -# The sink \bt_comp calls bt_message_iterator_next() on its upstream
68 -# bt_message_iterator_next() calls the source message iterator's
69 \link api-msg-iter-cls-meth-next "next" method\endlink.
71 @image html error-reporting-step-5.png
75 An error occurs within the "next" method of the source message
76 iterator: the function cannot read a file because permission was
80 @image html error-reporting-step-6.png
84 The source message iterator's "next" method appends the error
85 cause <em>"Cannot read file /some/file: permission denied"</em>
87 #BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR.
90 @image html error-reporting-step-7.png
94 bt_message_iterator_next() appends
95 the error cause <em>"Message iterator's 'next' method failed"</em>
96 with details about the source component and
97 returns #BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR.
100 @image html error-reporting-steps-89.png
104 The sink component's "consume" method appends the error
105 cause <em>"Cannot consume upstream message iterator's messages"</em>
106 and returns #BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR.
109 bt_graph_run() appends the error cause <em>"Component's 'consume'
110 method failed"</em> with details about the sink component and
111 returns #BT_GRAPH_RUN_STATUS_ERROR.
114 At this point, the current thread's error contains four causes:
116 - <em>"Cannot read file /some/file: permission denied"</em>
117 - <em>"Message iterator's 'next' method failed"</em>
118 - <em>"Cannot consume upstream message iterator's messages"</em>
119 - <em>"Component's 'consume' method failed"</em>
121 This list of error causes is much richer for the end user than dealing
122 only with #BT_GRAPH_RUN_STATUS_ERROR (the last error status code).
124 Both error (#bt_error) and error cause (#bt_error_cause) objects are
125 \ref api-fund-unique-object "unique objects":
127 - An error belongs to either
128 the library or you (see \ref api-error-handle "Handle an error").
130 - An error cause belongs to the error which contains it.
132 <h1>\anchor api-error-append-cause Append an error cause</h1>
134 When your function returns an error status code, use one of the
135 <code>bt_current_thread_error_append_cause_from_*()</code>
136 functions or <code>BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*()</code>
137 macros to append an error cause to the
138 current thread's error. Use the appropriate function or macro
139 depending on your function's actor amongst:
144 Append an error cause from a \bt_comp method.
146 Use bt_current_thread_error_append_cause_from_component() or
147 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT().
150 <dt>Message iterator</dt>
152 Append an error cause from a \bt_msg_iter method.
154 Use bt_current_thread_error_append_cause_from_message_iterator() or
155 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR().
158 <dt>Component class</dt>
160 Append an error cause from a \bt_comp_cls method
163 Use bt_current_thread_error_append_cause_from_component_class() or
164 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS().
169 Append an error cause from any other function, for example
170 a \bt_graph listener or a function of your user application).
172 Use bt_current_thread_error_append_cause_from_unknown() or
173 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN().
177 The <code>BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*()</code> macros
178 uses \c __FILE__ and \c __LINE__ as the file name and line number
179 parameters of their corresponding
180 <code>bt_current_thread_error_append_cause_from_*()</code> function.
182 <h1>\anchor api-error-handle Handle an error</h1>
184 If any libbabeltrace2 function you call returns an error status code, do
187 - Return an error status code too.
189 In that case, you \em can
190 \ref api-error-append-cause "append an error cause" to the current
193 - \em Take the current thread's error with
194 bt_current_thread_take_error().
196 This function moves the ownership of the error object from the library
199 At this point, you can inspect its causes with
200 bt_error_get_cause_count() and bt_error_borrow_cause_by_index(), and
203 - Call bt_error_release() to free the error object.
205 In <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>
206 terms, this corresponds to catching an exception and discarding it.
208 - Call bt_current_thread_move_error() to move back the error object's
209 ownership to the library.
211 In object-oriented programming terms, this corresponds to catching
212 an exception and rethrowing it.
214 bt_current_thread_clear_error() is a helper which is the equivalent of:
217 bt_error_release(bt_current_thread_take_error());
222 All error causes have the type #bt_error_cause.
224 There are four types of error cause actors:
231 Get the type enumerator of an error cause's actor with
232 bt_error_cause_get_actor_type().
234 An error cause has the following common properties:
239 Description of the error cause.
241 Use bt_error_cause_get_message().
246 Name of the module causing the error.
248 For example, libbabeltrace2 uses "libbabeltrace2" and the \bt_cli
249 CLI tool uses "Babeltrace CLI".
251 Use bt_error_cause_get_module_name().
256 Name of the source file causing the error.
258 Use bt_error_cause_get_file_name().
263 Line number of the statement causing the error.
265 Use bt_error_cause_get_line_number().
269 <h2>Error cause with a component actor</h2>
271 An error cause with a \bt_comp actor has the following specific
275 <dt>Component name</dt>
277 Name of the component.
279 Use bt_error_cause_component_actor_get_component_name().
282 <dt>Component class name</dt>
284 Name of the component's \ref api-comp-cls "class".
286 Use bt_error_cause_component_actor_get_component_class_type().
289 <dt>Component class type</dt>
291 Type of the component's class.
293 Use bt_error_cause_component_actor_get_component_class_name().
296 <dt>\bt_dt_opt Plugin name</dt>
298 Name of the \bt_plugin which provides the component's class, if any.
300 Use bt_error_cause_component_actor_get_plugin_name().
304 <h2>Error cause with a message iterator actor</h2>
306 An error cause with a \bt_msg_iter actor has the following specific
310 <dt>Component output port name</dt>
312 Name of the \bt_comp \bt_oport from which the message iterator
315 Use bt_error_cause_component_actor_get_component_name().
318 <dt>Component name</dt>
320 Name of the component.
322 Use bt_error_cause_component_actor_get_component_name().
325 bt_error_cause_message_iterator_actor_get_component_output_port_name
327 <dt>Component class name</dt>
329 Name of the component's \ref api-comp-cls "class".
331 Use bt_error_cause_component_actor_get_component_class_type().
334 <dt>Component class type</dt>
336 Type of the component's class.
338 Use bt_error_cause_component_actor_get_component_class_name().
341 <dt>\bt_dt_opt Plugin name</dt>
343 Name of the \bt_plugin which provides the component's class, if any.
345 Use bt_error_cause_component_actor_get_plugin_name().
349 <h2>Error cause with a component class actor</h2>
351 An error cause with a \bt_comp_cls actor has the following specific
355 <dt>Component class name</dt>
357 Name of the component class.
359 Use bt_error_cause_component_class_actor_get_component_class_type().
362 <dt>Component class type</dt>
364 Type of the component class.
366 Use bt_error_cause_component_class_actor_get_component_class_name().
369 <dt>\bt_dt_opt Plugin name</dt>
371 Name of the \bt_plugin which provides the component class, if any.
373 Use bt_error_cause_component_class_actor_get_plugin_name().
384 @typedef struct bt_error bt_error;
389 @typedef struct bt_error_cause bt_error_cause;
398 @name Current thread's error
404 \em Takes the current thread's error, that is, moves its ownership
405 from the library to the caller.
407 This function can return \c NULL if the current thread has no error.
409 Once you are done with the returned error, do one of:
411 - Call bt_error_release() to free the error object.
413 In <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>
414 terms, this corresponds to catching an exception and discarding it.
416 - Call bt_current_thread_move_error() to move back the error object's
417 ownership to the library.
419 In object-oriented programming terms, this corresponds to catching
420 an exception and rethrowing it.
423 Unique reference of the current thread's error, or \c NULL if the
424 current thread has no error.
427 <strong>If this function does not return <code>NULL</code></strong>,
428 the caller owns the returned error.
430 @sa bt_error_release() —
431 Releases (frees) an error.
432 @sa bt_current_thread_move_error() —
433 Moves an error's ownership to the library.
436 const bt_error
*bt_current_thread_take_error(void) __BT_NOEXCEPT
;
440 Moves the ownership of the error \bt_p{error} from the caller to
443 After you call this function, you don't own \bt_p{error} anymore.
445 In <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>
446 terms, calling this function corresponds to catching an
447 exception and rethrowing it.
449 You can instead release (free) the error with bt_error_release(), which,
450 in object-oriented programming terms,
451 corresponds to catching an exception and discarding it.
454 Error of which to move the ownership from you to the library.
456 @bt_pre_not_null{error}
458 The caller owns \bt_p{error}.
461 The library owns \bt_p{error}.
463 @sa bt_error_release() —
464 Releases (frees) an error.
465 @sa BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET() —
466 Calls this function and assigns \c NULL to the expression.
469 void bt_current_thread_move_error(const bt_error
*error
) __BT_NOEXCEPT
;
473 Moves the ownership of the error \bt_p{_error} from the caller to
474 the library, and then sets \bt_p{_error} to \c NULL.
477 Error of which to move the ownership from you to the library.
479 @bt_pre_not_null{_error}
480 @bt_pre_assign_expr{_error}
482 The caller owns \bt_p{_error}.
485 The library owns \bt_p{_error}.
487 @sa bt_current_thread_move_error() —
488 Moves an error's ownership to the library.
490 #define BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(_error) \
492 bt_current_thread_move_error(_error); \
498 Releases the current thread's error, if any.
500 This function is equivalent to:
503 bt_error_release(bt_current_thread_take_error());
507 The current thread has no error.
509 @sa bt_error_release() —
510 Releases (frees) an error.
511 @sa bt_current_thread_take_error —
512 Takes the current thread's error, moving its ownership from the
513 library to the caller.
516 void bt_current_thread_clear_error(void) __BT_NOEXCEPT
;
521 @name Error cause appending
528 <code>bt_current_thread_error_append_cause_from_*()</code>
531 typedef enum bt_current_thread_error_append_cause_status
{
536 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
= __BT_FUNC_STATUS_OK
,
542 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_MEMORY_ERROR
= __BT_FUNC_STATUS_MEMORY_ERROR
,
543 } bt_current_thread_error_append_cause_status
;
547 Appends an error cause to the current thread's error from a
550 This this a <code>printf()</code>-like function starting from the
551 format string parameter \bt_p{message_format}.
553 On success, the appended error cause's module name
554 (see bt_error_cause_get_module_name()) is:
557 NAME: CC-TYPE.PLUGIN-NAME.CC-NAME
563 NAME: CC-TYPE.CC-NAME
566 if no \bt_plugin provides the class of \bt_p{self_component}, with:
570 <dd>Name of \bt_p{self_component}.</dd>
574 Type of the \ref api-comp-cls "class" of \bt_p{self_component}
575 (\c src, \c flt, or \c sink).
578 <dt>\c PLUGIN-NAME</dt>
580 Name of the plugin which provides the class of
581 \bt_p{self_component}.
585 <dd>Name of the class of \bt_p{self_component}.</dd>
588 @param[in] self_component
589 Self component of the appending method.
591 Name of the source file containing the method which appends the
593 @param[in] line_number
594 Line number of the statement which appends the error cause.
595 @param[in] message_format
596 Format string which specifies how the function converts the
597 subsequent arguments (like <code>printf()</code>).
599 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
601 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_MEMORY_ERROR
604 @bt_pre_not_null{self_component}
605 @bt_pre_not_null{file_name}
606 @bt_pre_not_null{message_format}
607 @bt_pre_valid_fmt{message_format}
610 <strong>On success</strong>, the number of error causes in the
611 current thread's error is incremented.
613 @sa BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT() —
614 Calls this function with \c __FILE__ and \c __LINE__ as the
615 \bt_p{file_name} and \bt_p{line_number} parameters.
617 extern __BT_ATTR_FORMAT_PRINTF(4, 5)
618 bt_current_thread_error_append_cause_status
619 bt_current_thread_error_append_cause_from_component(
620 bt_self_component
*self_component
, const char *file_name
,
621 uint64_t line_number
,
622 const char *message_format
, ...) __BT_NOEXCEPT
;
626 Appends an error cause to the current thread's error from a
627 \bt_comp method using \c __FILE__ and \c __LINE__ as the source
628 file name and line number.
630 This macro calls bt_current_thread_error_append_cause_from_component()
631 with \c __FILE__ and \c __LINE__ as its
632 \bt_p{file_name} and \bt_p{line_number} parameters.
634 #define BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(_self_component, _message_format, ...) \
635 bt_current_thread_error_append_cause_from_component( \
636 (_self_component), __FILE__, __LINE__, (_message_format), ##__VA_ARGS__)
640 Appends an error cause to the current thread's error from a
643 This this a <code>printf()</code>-like function starting from the
644 format string parameter \bt_p{message_format}.
646 On success, the appended error cause's module name
647 (see bt_error_cause_get_module_name()) is:
650 COMP-NAME (OUT-PORT-NAME): CC-TYPE.PLUGIN-NAME.CC-NAME
656 COMP-NAME (OUT-PORT-NAME): CC-TYPE.CC-NAME
659 if no \bt_plugin provides the component class of
660 \bt_p{self_message_iterator}, with:
663 <dt>\c COMP-NAME</dt>
664 <dd>Name of the \bt_comp of \bt_p{self_message_iterator}.</dd>
666 <dt>\c OUT-PORT-NAME</dt>
668 Name of the \bt_oport from which \bt_p{self_message_iterator}.
674 Type of the \bt_comp_cls of \bt_p{self_message_iterator}
675 (\c src, \c flt, or \c sink).
678 <dt>\c PLUGIN-NAME</dt>
680 Name of the plugin which provides the component class of
681 \bt_p{self_message_iterator}.
685 <dd>Name of the component class of \bt_p{self_message_iterator}.</dd>
688 @param[in] self_message_iterator
689 Self message iterator of the appending method.
691 Name of the source file containing the method which appends the
693 @param[in] line_number
694 Line number of the statement which appends the error cause.
695 @param[in] message_format
696 Format string which specifies how the function converts the
697 subsequent arguments (like <code>printf()</code>).
699 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
701 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_MEMORY_ERROR
704 @bt_pre_not_null{self_message_iterator}
705 @bt_pre_not_null{file_name}
706 @bt_pre_not_null{message_format}
707 @bt_pre_valid_fmt{message_format}
710 <strong>On success</strong>, the number of error causes in the
711 current thread's error is incremented.
713 @sa BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR() —
714 Calls this function with \c __FILE__ and \c __LINE__ as the
715 \bt_p{file_name} and \bt_p{line_number} parameters.
717 extern __BT_ATTR_FORMAT_PRINTF(4, 5)
718 bt_current_thread_error_append_cause_status
719 bt_current_thread_error_append_cause_from_message_iterator(
720 bt_self_message_iterator
*self_message_iterator
,
721 const char *file_name
, uint64_t line_number
,
722 const char *message_format
, ...) __BT_NOEXCEPT
;
726 Appends an error cause to the current thread's error from a
727 \bt_msg_iter method using \c __FILE__ and \c __LINE__ as the source file
728 name and line number.
731 bt_current_thread_error_append_cause_from_message_iterator() with
732 \c __FILE__ and \c __LINE__ as its
733 \bt_p{file_name} and \bt_p{line_number} parameters.
735 #define BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(_self_message_iterator, _message_format, ...) \
736 bt_current_thread_error_append_cause_from_message_iterator( \
737 (_self_message_iterator), __FILE__, __LINE__, (_message_format), ##__VA_ARGS__)
741 Appends an error cause to the current thread's error from a
744 This this a <code>printf()</code>-like function starting from the
745 format string parameter \bt_p{message_format}.
747 As of \bt_name_version_min_maj, the only component class method is the
748 \ref api-qexec "query" method.
750 On success, the appended error cause's module name
751 (see bt_error_cause_get_module_name()) is:
754 CC-TYPE.PLUGIN-NAME.CC-NAME
763 if no \bt_plugin provides \bt_p{self_component_class}, with:
768 Type of \bt_p{self_component_class} (\c src, \c flt, or \c sink).
771 <dt>\c PLUGIN-NAME</dt>
773 Name of the plugin which provides \bt_p{self_component_class}.
777 <dd>Name of \bt_p{self_component_class}.</dd>
780 @param[in] self_component_class
781 Self component class of the appending method.
783 Name of the source file containing the method which appends the
785 @param[in] line_number
786 Line number of the statement which appends the error cause.
787 @param[in] message_format
788 Format string which specifies how the function converts the
789 subsequent arguments (like <code>printf()</code>).
791 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
793 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_MEMORY_ERROR
796 @bt_pre_not_null{self_component_class}
797 @bt_pre_not_null{file_name}
798 @bt_pre_not_null{message_format}
799 @bt_pre_valid_fmt{message_format}
802 <strong>On success</strong>, the number of error causes in the
803 current thread's error is incremented.
805 @sa BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS() —
806 Calls this function with \c __FILE__ and \c __LINE__ as the
807 \bt_p{file_name} and \bt_p{line_number} parameters.
809 extern __BT_ATTR_FORMAT_PRINTF(4, 5)
810 bt_current_thread_error_append_cause_status
811 bt_current_thread_error_append_cause_from_component_class(
812 bt_self_component_class
*self_component_class
,
813 const char *file_name
, uint64_t line_number
,
814 const char *message_format
, ...) __BT_NOEXCEPT
;
818 Appends an error cause to the current thread's error from a
819 component class method using \c __FILE__ and \c __LINE__ as the
820 source file name and line number.
823 bt_current_thread_error_append_cause_from_component_class()
824 with \c __FILE__ and \c __LINE__ as its
825 \bt_p{file_name} and \bt_p{line_number} parameters.
827 #define BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(_self_component_class, _message_format, ...) \
828 bt_current_thread_error_append_cause_from_component_class( \
829 (_self_component_class), __FILE__, __LINE__, (_message_format), ##__VA_ARGS__)
833 Appends an error cause to the current thread's error from any
836 Use this function when you cannot use
837 bt_current_thread_error_append_cause_from_component(),
838 bt_current_thread_error_append_cause_from_message_iterator(),
839 or bt_current_thread_error_append_cause_from_component_class().
841 This this a <code>printf()</code>-like function starting from the
842 format string parameter \bt_p{message_format}.
844 @param[in] module_name
845 Module name of the error cause to append.
847 Name of the source file containing the method which appends the
849 @param[in] line_number
850 Line number of the statement which appends the error cause.
851 @param[in] message_format
852 Format string which specifies how the function converts the
853 subsequent arguments (like <code>printf()</code>).
855 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
857 @retval #BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_MEMORY_ERROR
860 @bt_pre_not_null{module_name}
861 @bt_pre_not_null{file_name}
862 @bt_pre_not_null{message_format}
863 @bt_pre_valid_fmt{message_format}
866 <strong>On success</strong>, the number of error causes in the
867 current thread's error is incremented.
869 @sa BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN() —
870 Calls this function with \c __FILE__ and \c __LINE__ as the
871 \bt_p{file_name} and \bt_p{line_number} parameters.
873 extern __BT_ATTR_FORMAT_PRINTF(4, 5)
874 bt_current_thread_error_append_cause_status
875 bt_current_thread_error_append_cause_from_unknown(
876 const char *module_name
, const char *file_name
,
877 uint64_t line_number
,
878 const char *message_format
, ...) __BT_NOEXCEPT
;
882 Appends an error cause to the current thread's error from any
883 function using \c __FILE__ and \c __LINE__ as the source
884 file name and line number.
886 Use this function when you cannot use
887 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(),
888 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(),
889 or BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS().
891 This macro calls bt_current_thread_error_append_cause_from_unknown()
892 with \c __FILE__ and \c __LINE__ as its
893 \bt_p{file_name} and \bt_p{line_number} parameters.
895 #define BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(_module_name, _message_format, ...) \
896 bt_current_thread_error_append_cause_from_unknown( \
897 (_module_name), __FILE__, __LINE__, (_message_format), ##__VA_ARGS__)
908 Returns the number of error causes contained in the error
912 Error of which to get the number of contained error causes.
915 Number of contained error causes in \bt_p{error}.
917 @bt_pre_not_null{error}
920 uint64_t bt_error_get_cause_count(const bt_error
*error
) __BT_NOEXCEPT
;
924 Borrows the error cause at index \bt_p{index} from the
928 Error from which to borrow the error cause at index \bt_p{index}.
930 Index of the error cause to borrow from \bt_p{error}.
934 \em Borrowed reference of the error cause of
935 \bt_p{error} at index \bt_p{index}.
937 The returned pointer remains valid until \bt_p{error} is modified.
940 @bt_pre_not_null{error}
942 \bt_p{index} is less than the number of error causes in
943 \bt_p{error} (as returned by bt_error_get_cause_count()).
946 const bt_error_cause
*bt_error_borrow_cause_by_index(
947 const bt_error
*error
, uint64_t index
) __BT_NOEXCEPT
;
951 Releases (frees) the error \bt_p{error}.
953 After you call this function, \bt_p{error} does not exist.
955 Take the current thread's error with bt_current_thread_take_error().
957 In <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>
958 terms, calling this function corresponds to catching an
959 exception and discarding it.
961 You can instead move the ownership of \bt_p{error} to the library with
962 bt_current_thread_move_error(), which,
963 in object-oriented programming terms,
964 corresponds to catching an exception and rethrowing it.
967 Error to release (free).
969 @bt_pre_not_null{error}
972 \bt_p{error} does not exist.
974 @sa bt_current_thread_move_error() —
975 Moves an error's ownership to the library.
978 void bt_error_release(const bt_error
*error
) __BT_NOEXCEPT
;
983 @name Error cause: common
989 Error cause actor type enumerators.
991 typedef enum bt_error_cause_actor_type
{
996 BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN
= 1 << 0,
1002 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT
= 1 << 1,
1006 Component class method.
1008 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS
= 1 << 2,
1012 Message iterator method.
1014 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR
= 1 << 3,
1015 } bt_error_cause_actor_type
;
1019 Returns the actor type enumerator of the error cause
1022 @param[in] error_cause
1023 Error cause of which to get the actor type enumerator.
1026 Actor type enumerator of \bt_p{error_cause}.
1028 @bt_pre_not_null{error_cause}
1031 bt_error_cause_actor_type
bt_error_cause_get_actor_type(
1032 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1036 Returns the message of the error cause \bt_p{error_cause}.
1038 @param[in] error_cause
1039 Error cause of which to get the message.
1043 Message of \bt_p{error_cause}.
1045 The returned pointer remains valid as long as the error which
1046 contains \bt_p{error_cause} exists.
1049 @bt_pre_not_null{error_cause}
1052 const char *bt_error_cause_get_message(
1053 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1057 Returns the module name of the error cause \bt_p{error_cause}.
1059 @param[in] error_cause
1060 Error cause of which to get the module name.
1064 Module name of \bt_p{error_cause}.
1066 The returned pointer remains valid as long as the error which
1067 contains \bt_p{error_cause} exists.
1070 @bt_pre_not_null{error_cause}
1073 const char *bt_error_cause_get_module_name(
1074 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1078 Returns the name of the source file which contains the function
1079 which appended the error cause \bt_p{error_cause} to the
1080 current thread's error.
1082 @param[in] error_cause
1083 Error cause of which to get the source file name.
1087 Source file name of \bt_p{error_cause}.
1089 The returned pointer remains valid as long as the error which
1090 contains \bt_p{error_cause} exists.
1093 @bt_pre_not_null{error_cause}
1096 const char *bt_error_cause_get_file_name(
1097 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1101 Returns the line number of the statement
1102 which appended the error cause \bt_p{error_cause} to the
1103 current thread's error.
1105 @param[in] error_cause
1106 Error cause of which to get the source statement's line number.
1109 Source statement's line number of \bt_p{error_cause}.
1111 @bt_pre_not_null{error_cause}
1114 uint64_t bt_error_cause_get_line_number(
1115 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1120 @name Error cause with a component actor
1126 Returns the name of the \bt_comp of which a method
1127 appended the error cause \bt_p{error_cause} to the current
1130 @param[in] error_cause
1131 Error cause of which to get the component name.
1135 Component name of \bt_p{error_cause}.
1137 The returned pointer remains valid as long as the error which
1138 contains \bt_p{error_cause} exists.
1141 @bt_pre_not_null{error_cause}
1143 The actor type of \bt_p{error_cause} is
1144 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT.
1147 const char *bt_error_cause_component_actor_get_component_name(
1148 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1152 Returns the \ref api-comp-cls "class" type of the
1153 \bt_comp of which a method appended the error cause
1154 \bt_p{error_cause} to the current thread's error.
1156 @param[in] error_cause
1157 Error cause of which to get the component class type.
1160 Component class type of \bt_p{error_cause}.
1162 @bt_pre_not_null{error_cause}
1164 The actor type of \bt_p{error_cause} is
1165 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT.
1168 bt_component_class_type
bt_error_cause_component_actor_get_component_class_type(
1169 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1173 Returns the \ref api-comp-cls "class" name of the
1174 \bt_comp of which a method appended the error cause
1175 \bt_p{error_cause} to the current thread's error.
1177 @param[in] error_cause
1178 Error cause of which to get the component class name.
1182 Component class name of \bt_p{error_cause}.
1184 The returned pointer remains valid as long as the error which
1185 contains \bt_p{error_cause} exists.
1188 @bt_pre_not_null{error_cause}
1190 The actor type of \bt_p{error_cause} is
1191 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT.
1194 const char *bt_error_cause_component_actor_get_component_class_name(
1195 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1199 Returns the name of the \bt_plugin which provides the
1200 \ref api-comp-cls "class" of the \bt_comp of which a method
1201 appended the error cause \bt_p{error_cause} to the
1202 current thread's error.
1204 This function returns \c NULL if no plugin provides the error cause's
1207 @param[in] error_cause
1208 Error cause of which to get the plugin name.
1212 Plugin name of \bt_p{error_cause}, or \c NULL if no plugin
1213 provides the component class of \bt_p{error_cause}.
1215 The returned pointer remains valid as long as the error which
1216 contains \bt_p{error_cause} exists.
1219 @bt_pre_not_null{error_cause}
1221 The actor type of \bt_p{error_cause} is
1222 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT.
1225 const char *bt_error_cause_component_actor_get_plugin_name(
1226 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1231 @name Error cause with a message iterator actor
1237 Returns the name of the \bt_oport from which was created
1238 the message iterator of which the method
1239 appended the error cause \bt_p{error_cause} to the current
1242 @param[in] error_cause
1243 Error cause of which to get the output port name.
1247 Output port name of \bt_p{error_cause}.
1249 The returned pointer remains valid as long as the error which
1250 contains \bt_p{error_cause} exists.
1253 @bt_pre_not_null{error_cause}
1255 The actor type of \bt_p{error_cause} is
1256 #BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR.
1259 const char *bt_error_cause_message_iterator_actor_get_component_output_port_name(
1260 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1264 Returns the name of the \bt_comp of which a message iterator method
1265 appended the error cause \bt_p{error_cause} to the current
1268 @param[in] error_cause
1269 Error cause of which to get the component name.
1273 Component name of \bt_p{error_cause}.
1275 The returned pointer remains valid as long as the error which
1276 contains \bt_p{error_cause} exists.
1279 @bt_pre_not_null{error_cause}
1281 The actor type of \bt_p{error_cause} is
1282 #BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR.
1285 const char *bt_error_cause_message_iterator_actor_get_component_name(
1286 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1290 Returns the \ref api-comp-cls "class" type of the
1291 \bt_comp of which a message iterator method appended the error cause
1292 \bt_p{error_cause} to the current thread's error.
1294 @param[in] error_cause
1295 Error cause of which to get the component class type.
1298 Component class type of \bt_p{error_cause}.
1300 @bt_pre_not_null{error_cause}
1302 The actor type of \bt_p{error_cause} is
1303 #BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR.
1306 bt_component_class_type
1307 bt_error_cause_message_iterator_actor_get_component_class_type(
1308 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1312 Returns the \ref api-comp-cls "class" name of the
1313 \bt_comp of which a message iterator method appended the error cause
1314 \bt_p{error_cause} to the current thread's error.
1316 @param[in] error_cause
1317 Error cause of which to get the component class name.
1321 Component class name of \bt_p{error_cause}.
1323 The returned pointer remains valid as long as the error which
1324 contains \bt_p{error_cause} exists.
1327 @bt_pre_not_null{error_cause}
1329 The actor type of \bt_p{error_cause} is
1330 #BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR.
1333 const char *bt_error_cause_message_iterator_actor_get_component_class_name(
1334 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1338 Returns the name of the \bt_plugin which provides the
1339 \ref api-comp-cls "class" of the \bt_comp of which a
1340 message iterator method
1341 appended the error cause \bt_p{error_cause} to the
1342 current thread's error.
1344 This function returns \c NULL if no plugin provides the error cause's
1347 @param[in] error_cause
1348 Error cause of which to get the plugin name.
1352 Plugin name of \bt_p{error_cause}, or \c NULL if no plugin
1353 provides the component class of \bt_p{error_cause}.
1355 The returned pointer remains valid as long as the error which
1356 contains \bt_p{error_cause} exists.
1359 @bt_pre_not_null{error_cause}
1361 The actor type of \bt_p{error_cause} is
1362 #BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR.
1365 const char *bt_error_cause_message_iterator_actor_get_plugin_name(
1366 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1371 @name Error cause with a component class actor
1377 Returns the name of the \bt_comp_cls
1378 of which a method appended the error cause
1379 \bt_p{error_cause} to the current thread's error.
1381 @param[in] error_cause
1382 Error cause of which to get the component class name.
1385 Component class name of \bt_p{error_cause}.
1387 @bt_pre_not_null{error_cause}
1389 The actor type of \bt_p{error_cause} is
1390 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS.
1393 bt_component_class_type
1394 bt_error_cause_component_class_actor_get_component_class_type(
1395 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1399 Returns the name of the \bt_comp_cls
1400 of which a method appended the error cause
1401 \bt_p{error_cause} to the current thread's error.
1403 @param[in] error_cause
1404 Error cause of which to get the component class name.
1408 Component class name of \bt_p{error_cause}.
1410 The returned pointer remains valid as long as the error which
1411 contains \bt_p{error_cause} exists.
1414 @bt_pre_not_null{error_cause}
1416 The actor type of \bt_p{error_cause} is
1417 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS.
1420 const char *bt_error_cause_component_class_actor_get_component_class_name(
1421 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1425 Returns the name of the \bt_plugin which provides the
1426 \bt_comp_cls of which a method
1427 appended the error cause \bt_p{error_cause} to the
1428 current thread's error.
1430 This function returns \c NULL if no plugin provides the error cause's
1433 @param[in] error_cause
1434 Error cause of which to get the plugin name.
1438 Plugin name of \bt_p{error_cause}, or \c NULL if no plugin
1439 provides the component class of \bt_p{error_cause}.
1441 The returned pointer remains valid as long as the error which
1442 contains \bt_p{error_cause} exists.
1445 @bt_pre_not_null{error_cause}
1447 The actor type of \bt_p{error_cause} is
1448 #BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS.
1451 const char *bt_error_cause_component_class_actor_get_plugin_name(
1452 const bt_error_cause
*error_cause
) __BT_NOEXCEPT
;
1462 #endif /* BABELTRACE2_ERROR_REPORTING_H */