Module: Mbeditor::ExceptionLog
- Defined in:
- lib/mbeditor/exception_log.rb
Overview
A bounded, in-memory ring of exceptions raised by the host app, so a failed request shows up in the editor instead of only in the log.
Lives in lib/ (required from lib/mbeditor.rb, NOT autoloaded) for the same reason as RubyLspClient: a Zeitwerk reload in the host's dev environment must not wipe the buffer you are trying to read.
Fed by an ActiveSupport::Notifications subscriber wired up in the engine. A Rack middleware cannot be used here: ActionDispatch::DebugExceptions rescues and renders the error, so nothing outside it ever sees the raise.
Constant Summary collapse
- MAX_ENTRIES =
50- MAX_FRAMES =
Backtraces are mostly framework and gem frames, which this editor cannot open and which push the app's own frames off the end.
10
Class Method Summary collapse
- .clear! ⇒ Object
-
.entries ⇒ Object
Newest first — the one you just triggered is the one you want.
-
.record(exception, payload = {}, workspace_root: nil) ⇒ Object
Returns the recorded entry, or nil when there was nothing to record.
Class Method Details
.clear! ⇒ Object
43 44 45 46 |
# File 'lib/mbeditor/exception_log.rb', line 43 def clear! MUTEX.synchronize { @entries = [] } nil end |
.entries ⇒ Object
Newest first — the one you just triggered is the one you want.
39 40 41 |
# File 'lib/mbeditor/exception_log.rb', line 39 def entries MUTEX.synchronize { (@entries || []).reverse } end |
.record(exception, payload = {}, workspace_root: nil) ⇒ Object
Returns the recorded entry, or nil when there was nothing to record.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mbeditor/exception_log.rb', line 26 def record(exception, payload = {}, workspace_root: nil) return nil if exception.nil? entry = build(exception, payload, workspace_root) MUTEX.synchronize do @entries ||= [] @entries << entry @entries.shift while @entries.length > MAX_ENTRIES end entry end |