Class: Bugsage::ErrorPage

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsage/error_page.rb

Class Method Summary collapse

Class Method Details

.format_value(value) ⇒ Object



287
288
289
290
291
292
293
294
295
296
# File 'lib/bugsage/error_page.rb', line 287

def self.format_value(value)
  case value
  when Hash, Array
    JSON.pretty_generate(value)
  when NilClass
    Bugsage.t("common.not_available")
  else
    value.to_s
  end
end

.render(suggestion, context = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/bugsage/error_page.rb', line 8

def self.render(suggestion, context = {})
  file_path, line_number = CodeContext.extract_location(suggestion.location)
  code_context = CodeContext.render_code_context(file_path, line_number)

  <<~HTML
            <!DOCTYPE html>
            <html>
            <head>
              <meta charset="utf-8">
              <title>#{CodeContext.escape_html(Bugsage.t("ui.error_page.title", issue: suggestion.issue))}</title>
              <style>
                * { box-sizing: border-box; }
                body {
                  background: linear-gradient(135deg, #1e1e2e 0%, #2a2a3e 100%);
                  color: #cdd6f4;
                  font-family: 'SF Mono', Consolas, 'Courier New', monospace;
                  padding: 0;
                  margin: 0;
                  min-height: 100vh;
                }
                .container {
                  max-width: 1000px;
                  margin: 0 auto;
                  padding: 40px 20px;
                }
                h1 {
                  color: #f38ba8;
                  font-size: 32px;
                  margin: 0 0 24px 0;
                  display: flex;
                  align-items: center;
                  gap: 12px;
                }
                .header-info {
                  background: rgba(63, 63, 95, 0.5);
                  border-left: 4px solid #f38ba8;
                  padding: 16px;
                  border-radius: 4px;
                  margin-bottom: 24px;
                }
                .header-info p {
                  margin: 8px 0;
                  font-size: 14px;
                }
                .code-section {
                  background: #313244;
                  border-radius: 8px;
                  margin: 24px 0;
                  overflow: hidden;
                  border: 1px solid #45475a;
                }
                .code-header {
                  background: #45475a;
                  padding: 12px 16px;
                  border-bottom: 1px solid #585869;
                  color: #a6e3a1;
                  font-size: 12px;
                  font-weight: bold;
                }
                .code-block {
                  background: #1e1e2e;
                  padding: 0;
                  max-height: 600px;
                  overflow-y: auto;
                }
                .code-line {
                  display: flex;
                  border-bottom: 1px solid #45475a;
                }
                .code-line:last-child {
                  border-bottom: none;
                }
                .code-line-number {
                  background: #313244;
                  color: #6e7086;
                  padding: 8px 16px;
                  text-align: right;
                  min-width: 60px;
                  border-right: 1px solid #45475a;
                  user-select: none;
                  font-size: 12px;
                }
                .code-line-content {
                  flex: 1;
                  padding: 8px 16px;
                  white-space: pre;
                  overflow-x: auto;
                  font-size: 13px;
                  color: #cdd6f4;
                }
                .code-line.error {
                  background: rgba(243, 139, 168, 0.1);
                  border-left: 3px solid #f38ba8;
                }
                .code-line.error .code-line-number {
                  background: rgba(243, 139, 168, 0.2);
                  color: #f38ba8;
                  font-weight: bold;
                }
                #{InlineConsole.styles}
                #{AiPanel.styles}
                .section {
                  margin-top: 24px;
                }
                .label {
                  color: #89b4fa;
                  text-transform: uppercase;
                  font-size: 11px;
                  letter-spacing: 2px;
                  margin-bottom: 12px;
                  font-weight: bold;
                }
                .value {
                  background: #313244;
                  padding: 12px 16px;
                  border-radius: 6px;
                  word-break: break-all;
                  white-space: pre-wrap;
                  border-left: 3px solid #89b4fa;
                }
                .message-box {
                  background: rgba(243, 139, 168, 0.1);
                  border-left: 4px solid #f38ba8;
                  padding: 16px;
                  border-radius: 4px;
                  margin-bottom: 24px;
                  color: #f5c2e7;
                }
                .fixes {
                  list-style: none;
                  padding: 0;
                  margin: 0;
                }
                .fixes li {
                  background: rgba(166, 227, 161, 0.1);
                  padding: 12px 16px;
                  border-radius: 6px;
                  margin-bottom: 8px;
                  border-left: 3px solid #a6e3a1;
                }
                .fixes li::before {
                  content: "✓ ";
                  color: #a6e3a1;
                  font-weight: bold;
                }
                .confidence {
                  display: inline-block;
                  background: #a6e3a1;
                  color: #1e1e2e;
                  padding: 6px 16px;
                  border-radius: 20px;
                  font-weight: bold;
                  font-size: 13px;
                }
                .source-badge {
                  display: inline-block;
                  background: rgba(137, 180, 250, 0.2);
                  color: #89b4fa;
                  padding: 4px 12px;
                  border-radius: 999px;
                  font-size: 12px;
                  font-weight: bold;
                  margin-top: 8px;
                }
                .ai-notes {
                  background: rgba(137, 180, 250, 0.1);
                  border-left: 4px solid #89b4fa;
                  padding: 16px;
                  border-radius: 4px;
                  margin: 24px 0;
                  color: #cdd6f4;
                  white-space: pre-wrap;
                }
                .ai-error {
                  background: rgba(250, 179, 135, 0.1);
                  border-left: 4px solid #fab387;
                  padding: 16px;
                  border-radius: 4px;
                  margin: 24px 0;
                  color: #f9e2af;
                  white-space: pre-wrap;
                }
                .row {
                  display: grid;
                  grid-template-columns: 1fr 1fr;
                  gap: 24px;
                  margin-bottom: 24px;
                }
                @media (max-width: 768px) {
                  .row { grid-template-columns: 1fr; }
                }
              </style>
            </head>
            <body>
              <div class="container">
                <h1>#{CodeContext.escape_html(Bugsage.t("ui.error_page.caught", issue: suggestion.issue))}</h1>

                <div class="header-info">
                  <p><strong>#{CodeContext.escape_html(Bugsage.t("ui.error_page.location_label"))}</strong> \
    #{CodeContext.escape_html(suggestion.location)}</p>
                  #{render_source_badge(suggestion)}
                </div>

                #{code_context}

                <div class="message-box">
                  <strong>#{CodeContext.escape_html(Bugsage.t("ui.error_page.error_message"))}</strong><br>
                  #{CodeContext.escape_html(suggestion.root_cause)}
                </div>

                #{InlineConsole.render_panel}

                #{render_request_context(context)}

                #{AiPanel.render_panel(suggestion: suggestion, include_script: false)}

                <div class="row">
                  <div class="section">
                    <div class="label">#{CodeContext.escape_html(Bugsage.t("ui.error_page.suggested_fixes"))}</div>
                    <ul class="fixes" id="bugsage-fixes">
                      #{suggestion.fixes.map { |f| "<li>#{CodeContext.escape_html(f)}</li>" }.join}
                    </ul>
                  </div>
                  <div class="section">
                    <div class="label">#{CodeContext.escape_html(Bugsage.t("ui.error_page.confidence_level"))}</div>
                    <div style="padding-top: 12px;">
                      <span class="confidence" id="bugsage-confidence">\
    #{CodeContext.escape_html(Bugsage.t("ui.error_page.confidence_value", confidence: suggestion.confidence))}</span>
                    </div>
                  </div>
                </div>
              </div>
              #{AiPanel.render_script if Bugsage.configuration.ai_configured?}
            </body>
            </html>
  HTML
end

.render_ai_error(ai_error) ⇒ Object



276
277
278
279
280
281
282
283
284
285
# File 'lib/bugsage/error_page.rb', line 276

def self.render_ai_error(ai_error)
  return "" if ai_error.to_s.strip.empty?

  <<~HTML
    <div class="section">
      <div class="label">#{CodeContext.escape_html(Bugsage.t("ui.error_page.ai_status"))}</div>
      <div class="ai-error">#{CodeContext.escape_html(Bugsage.t("ui.error_page.ai_error", error: ai_error))}</div>
    </div>
  HTML
end

.render_ai_notes(suggestion) ⇒ Object



265
266
267
268
269
270
271
272
273
274
# File 'lib/bugsage/error_page.rb', line 265

def self.render_ai_notes(suggestion)
  return "" if suggestion.ai_notes.to_s.strip.empty?

  <<~HTML
    <div class="section">
      <div class="label">#{CodeContext.escape_html(Bugsage.t("ui.error_page.ai_notes"))}</div>
      <div class="ai-notes">#{CodeContext.escape_html(suggestion.ai_notes)}</div>
    </div>
  HTML
end

.render_request_context(context) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
# File 'lib/bugsage/error_page.rb', line 246

def self.render_request_context(context)
  return "" if context.empty?

  rows = context.map do |label, value|
    "<div class=\"section\"><div class=\"label\">#{CodeContext.escape_html(label)}</div>" \
      "<div class=\"value\">#{CodeContext.escape_html(format_value(value))}</div></div>"
  end.join

  label = CodeContext.escape_html(Bugsage.t("ui.error_page.rails_request_context"))
  "<div class=\"section\"><div class=\"label\">#{label}</div>#{rows}</div>"
end

.render_source_badge(suggestion) ⇒ Object



258
259
260
261
262
263
# File 'lib/bugsage/error_page.rb', line 258

def self.render_source_badge(suggestion)
  return "" unless suggestion.ai_enhanced?

  badge = CodeContext.escape_html(Bugsage.t("ui.error_page.ai_enhanced_analysis"))
  "<p><span class=\"source-badge\">#{badge}</span></p>"
end