error_get_full_trace Function

private function error_get_full_trace(self) result(trace)

Get complete error message with cause chain and stack trace Returns a dynamically-sized multi-line string

Type Bound

error_t

Arguments

Type IntentOptional Attributes Name
class(error_t), intent(in) :: self

Return Value character(len=:), allocatable


Calls

proc~~error_get_full_trace~~CallsGraph proc~error_get_full_trace error_t%error_get_full_trace proc~code_to_string code_to_string proc~error_get_full_trace->proc~code_to_string proc~error_has_error error_t%error_has_error proc~error_get_full_trace->proc~error_has_error

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: i
character(len=32), private :: idx_str

Source Code

   function error_get_full_trace(self) result(trace)
      !! Get complete error message with cause chain and stack trace
      !! Returns a dynamically-sized multi-line string
      class(error_t), intent(in) :: self
      character(len=:), allocatable :: trace
      character(len=32) :: idx_str
      integer(default_int) :: i

      if (.not. self%has_error()) then
         trace = ""
         return
      end if

      ! Top-level error with named code
      trace = code_to_string(self%code)//": "
      if (allocated(self%message)) then
         trace = trace//self%message
      end if

      ! Cause chain: prints from most-recent wrap (cause_depth) down to
      ! root cause (1), matching Rust's "caused by" display order
      do i = self%cause_depth, 1, -1
         trace = trace//new_line('a')//"  Caused by: "// &
                 trim(code_to_string(self%cause_codes(i)))//": "// &
                 trim(self%cause_messages(i))
      end do

      ! Stack trace
      if (self%stack_depth > 0) then
         trace = trace//new_line('a')//"Call stack (most recent first):"
         do i = self%stack_depth, 1, -1
            write (idx_str, '(I0)') i
            trace = trace//new_line('a')//"  ["//trim(idx_str)//"] "// &
                    trim(self%call_stack(i))
         end do
      end if
   end function error_get_full_trace