Add a call location to the stack trace Typically called when propagating errors upward
Example: call some_routine(…, err) if (err%has_error()) then call err%add_context(“pic_module:my_subroutine”) return end if
Locations are stored in fixed MAX_LOCATION_LEN slots. A location
that does not fit is truncated from the LEFT and prefixed with
TRUNCATION_MARKER, because these are overwhelmingly
"src/lib/core/error/pic_error.F90"//":"//to_char(__LINE__) strings whose useful end is the
line number: in a CI build tree the absolute path alone can exceed
the slot, and clipping the tail would throw away the only part
anybody reads.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(inout) | :: | self | |||
| character(len=*), | intent(in) | :: | location |
pure subroutine error_add_context(self, location) !! Add a call location to the stack trace !! Typically called when propagating errors upward !! !! Example: !! call some_routine(..., err) !! if (err%has_error()) then !! call err%add_context("pic_module:my_subroutine") !! return !! end if !! !! Locations are stored in fixed MAX_LOCATION_LEN slots. A location !! that does not fit is truncated from the LEFT and prefixed with !! TRUNCATION_MARKER, because these are overwhelmingly !! `__FILE__//":"//to_char(__LINE__)` strings whose useful end is the !! line number: in a CI build tree the absolute path alone can exceed !! the slot, and clipping the tail would throw away the only part !! anybody reads. class(error_t), intent(inout) :: self character(len=*), intent(in) :: location if (self%stack_depth < MAX_STACK_DEPTH) then self%stack_depth = self%stack_depth + 1 self%call_stack(self%stack_depth) = clip_head(location) end if end subroutine error_add_context