Skip to content

Commit a5a9d38

Browse files
committed
Add version logging to error reports
1 parent 6a7653b commit a5a9d38

7 files changed

Lines changed: 59 additions & 14 deletions

File tree

app/assets/stylesheets/forms.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ select.form-element {
3131
& > .actions {
3232
display: flex;
3333
align-items: flex-end;
34+
margin: 4px 0;
3435
}
3536
}
3637

app/controllers/admin_controller.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@ class AdminController < ApplicationController
99
def index; end
1010

1111
def error_reports
12-
@reports = if params[:uuid].present?
13-
ErrorLog.where(uuid: params[:uuid])
14-
elsif current_user.is_global_admin
15-
ErrorLog.all
16-
else
17-
ErrorLog.where(community: RequestContext.community)
18-
end.newest_first.paginate(page: params[:page], per_page: 50)
12+
base_scope = if current_user.is_global_admin
13+
ErrorLog.all
14+
else
15+
ErrorLog.where(community: RequestContext.community)
16+
end
17+
18+
if params[:uuid].present?
19+
base_scope = base_scope.where(uuid: params[:uuid])
20+
end
21+
22+
if params[:version].present? && params[:version] == 'current'
23+
sha, _date = helpers.current_commit
24+
base_scope = base_scope.where(version: sha)
25+
elsif params[:version].present?
26+
base_scope = base_scope.where(version: params[:version])
27+
end
28+
29+
@reports = base_scope.newest_first.paginate(page: params[:page], per_page: 50)
30+
render layout: 'without_sidebar'
1931
end
2032

2133
def privileges

app/controllers/errors_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ def error
2020
end
2121

2222
if @exception.present? && [422, 500].include?(@status)
23+
sha, _date = helpers.current_commit
2324
@log = ErrorLog.create(community: RequestContext.community, user: current_user, klass: @exception&.class,
2425
message: @exception&.message, backtrace: @exception&.backtrace&.join("\n"),
2526
request_uri: request.original_url, host: request.raw_host_with_port,
26-
uuid: SecureRandom.uuid, user_agent: request.user_agent)
27+
uuid: SecureRandom.uuid, user_agent: request.user_agent, version: sha)
2728
end
2829

2930
render views[@status] || 'errors/error', formats: :html, status: @status, layout: 'without_sidebar'

app/views/admin/error_reports.html.erb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
<h1><%= t 'admin.tools.error_reports' %></h1>
22
<p class="is-lead"><%= pluralize(@reports.count, t('g.error')) %> <%= t 'g.logged' %></p>
33

4-
<%= form_tag admin_error_reports_path, method: :get, class: 'has-margin-bottom-4' do %>
5-
<%= label_tag :uuid, t('admin.error_search_uuid') %>
6-
<%= text_field_tag :uuid, params[:uuid], class: 'form-element', placeholder: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' %>
7-
<%= submit_tag t('g.search').capitalize, class: 'button is-filled' %>
8-
<% end %>
4+
<div class="flex-row">
5+
<%= form_tag admin_error_reports_path, method: :get, class: 'has-margin-bottom-4 primary' do %>
6+
<div class="form-group-horizontal">
7+
<div class="form-group">
8+
<%= label_tag :uuid, t('admin.error_search_uuid') %>
9+
<%= text_field_tag :uuid, params[:uuid], class: 'form-element', placeholder: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' %>
10+
</div>
11+
<div class="actions">
12+
<%= submit_tag t('g.search').capitalize, class: 'button is-filled' %>
13+
</div>
14+
</div>
15+
<% end %>
16+
17+
<%= form_tag admin_error_reports_path, method: :get, class: 'has-margin-bottom-4 primary' do %>
18+
<div class="form-group-horizontal">
19+
<div class="form-group">
20+
<%= label_tag :uuid, t('admin.error_search_version') %>
21+
<%= text_field_tag :uuid, params[:uuid], class: 'form-element', placeholder: '(full SHA)' %>
22+
</div>
23+
<div class="actions">
24+
<div class="button-list">
25+
<button type="submit" class="button is-filled"><%= t('g.search').capitalize %></button>
26+
<%= link_to 'Current', query_url(version: 'current'), class: 'button is-outlined' %>
27+
</div>
28+
</div>
29+
</div>
30+
<% end %>
31+
</div>
32+
933

1034
<% @reports.each do |report| %>
1135
<%= render 'error_report', report: report %>

config/locales/strings/en.admin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ en:
1616
organisation-wide changes like privacy policy or TOS changes. Format in a way that will be legible when Markdown
1717
is removed.
1818
error_search_uuid: 'Search for an error UUID'
19+
error_search_version: 'Errors from version (commit)'
1920
privileges_blurb: >
2021
Here you can define the reputation required to gain each available privilege. Click on a value to edit it.
2122
email_query_blurb: >
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddVersionToErrorLogs < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :error_logs, :version, :string
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_09_05_231140) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_09_20_103432) do
1414
create_table "abilities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
1515
t.bigint "community_id"
1616
t.string "name"
@@ -253,6 +253,7 @@
253253
t.datetime "updated_at", precision: nil, null: false
254254
t.string "uuid"
255255
t.string "user_agent"
256+
t.string "version"
256257
t.index ["community_id"], name: "index_error_logs_on_community_id"
257258
t.index ["user_id"], name: "index_error_logs_on_user_id"
258259
end

0 commit comments

Comments
 (0)