{"record":{"id":"6129b7b7d1c3900b","repo":"sj26/mailcatcher","slug":"message-context-inspect","errorCode":null,"errorMessage":"*** #{message}: #{context.inspect}","messagePattern":"\\*\\*\\* #(.+?): #(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/mail_catcher.rb","lineNumber":61,"sourceCode":"\n  def browsable?\n    windows? or which? \"open\"\n  end\n\n  def browse url\n    if windows?\n      system \"start\", \"/b\", url\n    elsif which? \"open\"\n      system \"open\", url\n    end\n  end\n\n  def log_exception(message, context, exception)\n    gems_paths = (Gem.path | [Gem.default_dir]).map { |path| Regexp.escape(path) }\n    gems_regexp = %r{(?:#{gems_paths.join(\"|\")})/gems/([^/]+)-([\\w.]+)/(.*)}\n    gems_replace = '\\1 (\\2) \\3'\n\n    puts \"*** #{message}: #{context.inspect}\"\n    puts \"    Exception: #{exception}\"\n    puts \"    Backtrace:\", *exception.backtrace.map { |line| \"       #{line.sub(gems_regexp, gems_replace)}\" }\n    puts \"    Please submit this as an issue at https://github.com/sj26/mailcatcher/issues\"\n  end\n\n  @@defaults = {\n    :smtp_ip => \"127.0.0.1\",\n    :smtp_port => \"1025\",\n    :http_ip => \"127.0.0.1\",\n    :http_port => \"1080\",\n    :http_path => \"/\",\n    :messages_limit => nil,\n    :verbose => false,\n    :daemon => !windows?,\n    :browse => false,\n    :quit => true,\n  }\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/sj26/mailcatcher/blob/18a9cb7a79b321b2bcb51608dd793ea51255189e/lib/mail_catcher.rb#L43-L79","documentation":"This is the header line of MailCatcher's catch-all crash reporter, log_exception (lib/mail_catcher.rb:56-65). It is not raised; it is printed when an internal `rescue => exception` in SMTP message handling (smtp.rb:62) or the websocket bus push (application.rb:89) catches an unexpected exception and logs `*** <message>: <context.inspect>`. The context is the @current_message hash (sender/recipients/source) or the bus message that was being processed when the failure occurred.","triggerScenarios":"Any exception raised inside MailCatcher::Mail.add_message while persisting a received email: SQLite3 errors from the in-memory DB inserts (mail.rb:45-57), Mail.new(source) raising on pathological MIME, or a nil `message[:source]` when receive_message is called without a preceding data chunk; it also prefixes the websocket-send failure logged from application.rb:90.","commonSituations":"Upgrading the sqlite3 gem past what this MailCatcher version supports (e.g. 1.4.x rejecting strings containing null bytes in the message source); sending mail with broken/8-bit headers or huge attachments from ActionMailer; combining an old mailcatcher gem with a new Ruby; checking the log after seeing SMTP clients get a 451-style failure.","solutions":["Read the next two lines of the same report (`Exception:` and `Backtrace:`) — they name the real error class and the failing gem frame; fix that first.","Run in the foreground with verbosity so output is not lost to daemonization: `mailcatcher --foreground --verbose`.","If the Exception line mentions SQLite3/null bytes or argument errors, align gem versions: `gem uninstall sqlite3; gem install sqlite3 -v 1.3.13` (or upgrade the mailcatcher gem to the latest release, which pins a compatible sqlite3).","Reproduce with a minimal email (plain text, ASCII headers) to confirm whether malformed MIME content is the trigger; if it is, fix or normalize what the sending app delivers.","If the backtrace shows a genuine MailCatcher bug, follow the printed advice and file it at https://github.com/sj26/mailcatcher/issues with the full block."],"exampleFix":"# before: exception inside add_message surfaces only as\n# *** Error receiving message: {:sender=>\"app@example.com\", ...}\n\n# after: capture the full report when triaging\nmailcatcher --foreground --verbose 2>&1 | tee mailcatcher.log\n# then align the known-incompatible gem\n# Gemfile: gem \"sqlite3\", \"~> 1.3.6\"  ->  bundle update sqlite3 mailcatcher","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"# The library already rescues; the guard a caller/embedder needs is around its own hooks.\n# If you drive MailCatcher as a library and reuse MailCatcher::Mail:\nbegin\n  MailCatcher::Mail.add_message(sender: \"app@example.com\", recipients: [\"to@example.com\"], source: raw_rfc2822)\nrescue => e\n  warn \"persistence failed for #{raw_rfc2822.bytesize} bytes: #{e.class}: #{e.message}\"\n  # keep the raw mail on disk so it is not lost when the report fires\n  File.binwrite(\"failed/#{Time.now.to_i}.eml\", raw_rfc2822)\nend","preventionTips":["Run `mailcatcher --foreground --verbose` whenever you change gems so reports are seen, not swallowed by daemon mode.","Pin or jointly upgrade mailcatcher + sqlite3 + mail; the classic regression is a newer sqlite3 rejecting binary message sources.","Send well-formed mail from apps (proper Content-Type/charset headers) instead of raw sockets when possible.","When embedding, prefer MailCatcher::Mail.add_message wrapped in your own rescue instead of depending on the internal report."],"tags":["logging","exception-reporting","diagnostics","smtp","websocket"],"backgroundTag":"exception-logging","analyzedSha":"18a9cb7a79b321b2bcb51608dd793ea51255189e","analyzedAt":"2026-08-21T18:56:10.605Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}