Skip to content

Commit

Permalink
Start looking into better error surfacing
Browse files Browse the repository at this point in the history
  • Loading branch information
hopsoft committed Mar 4, 2024
1 parent 5d9d683 commit 46a9e2f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/@turbo-boost/commands.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/assets/builds/@turbo-boost/commands.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions app/javascript/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ const logEvent = event => {
const typeParts = type.split(':')
const lastPart = typeParts.pop()
const eventName = `%c${typeParts.join(':')}:%c${lastPart}`
const message = [`%c${commandName}`, `%c${duration}`, eventName, `%c${id}`]
const message = [`%c${commandName}`, `%c${duration}`, eventName]

console.log(
message.join(' ').replace(/\s{2,}/g, ' '),
'color:deepskyblue',
'color:lime',
'color:darkgray',
eventName.match(/abort|error/i) ? 'color:red' : 'color:deepskyblue',
'color:silver',
{ detail, target }
{ id, detail, target }
)
}
}
Expand Down
11 changes: 8 additions & 3 deletions lib/turbo_boost/commands/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,19 @@ def add_state
end

def add_event(name, detail = {})
detail = command_params.to_h.merge(detail).deep_transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
detail = command_params.to_unsafe_hash
.except(:state_collection)
.merge(detail)
.deep_transform_keys! { |key| key.to_s.camelize(:lower).to_sym }

options = {
args: [name, {
bubbles: true,
cancelable: false,
detail: detail
detail: detail.except(:stateCollection)
}]
}

options[:selector] = "##{command_instance.element.id}" if command_instance&.element&.id
add_content turbo_stream.invoke(:dispatch_event, **options)
end
Expand Down Expand Up @@ -315,7 +320,7 @@ def add_error_alert
Finally, check server logs for additional info.
MSG

add_content turbo_stream.invoke(:alert, args: [message.strip])
add_content turbo_stream.invoke(:alert, args: [message.strip], delay: 100)
end

def add_header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def perform_with_abort
end

def perform_with_error
raise NotImplementedError
raise NotImplementedError, "Intentional error for testing!"
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand Down

0 comments on commit 46a9e2f

Please sign in to comment.