Exception: GraphQL::Backtrace::TracedError

Inherits:
Error
  • Object
show all
Defined in:
lib/graphql/backtrace/traced_error.rb

Overview

When GraphQL::Backtrace is enabled, raised errors are wrapped with TracedError.

Constant Summary collapse

MESSAGE_TEMPLATE =
<<-MESSAGE
Unhandled error during GraphQL execution:

  %{cause_message}
    %{cause_backtrace}
    %{cause_backtrace_more}
Use #cause to access the original exception (including #cause.backtrace).

GraphQL Backtrace:
%{graphql_table}
MESSAGE
CAUSE_BACKTRACE_PREVIEW_LENGTH =

This many lines of the original Ruby backtrace are included in the message

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(err, current_ctx) ⇒ TracedError



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/graphql/backtrace/traced_error.rb', line 29

def initialize(err, current_ctx)
  @context = current_ctx
  backtrace = Backtrace.new(current_ctx, value: err)
  @graphql_backtrace = backtrace.to_a

  cause_backtrace_preview = err.backtrace.first(CAUSE_BACKTRACE_PREVIEW_LENGTH).join("\n    ")

  cause_backtrace_remainder_length = err.backtrace.length - CAUSE_BACKTRACE_PREVIEW_LENGTH
  cause_backtrace_more = if cause_backtrace_remainder_length < 0
    ""
  elsif cause_backtrace_remainder_length == 1
    "... and 1 more line\n"
  else
    "... and #{cause_backtrace_remainder_length} more lines\n"
  end

  message = MESSAGE_TEMPLATE % {
    cause_message: err.message,
    cause_backtrace: cause_backtrace_preview,
    cause_backtrace_more: cause_backtrace_more,
    graphql_table: backtrace.inspect,
  }
  super(message)
end

Instance Attribute Details

#contextGraphQL::Query::Context (readonly)



11
12
13
# File 'lib/graphql/backtrace/traced_error.rb', line 11

def context
  @context
end

#graphql_backtraceArray<String> (readonly)



8
9
10
# File 'lib/graphql/backtrace/traced_error.rb', line 8

def graphql_backtrace
  @graphql_backtrace
end