error_add_context Subroutine

private 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 "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 Bound

error_t

Arguments

Type IntentOptional Attributes Name
class(error_t), intent(inout) :: self
character(len=*), intent(in) :: location

Calls

proc~~error_add_context~~CallsGraph proc~error_add_context error_t%error_add_context proc~clip_head clip_head proc~error_add_context->proc~clip_head

Source Code

   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