Attach error stack and log tail to Slack on crash#6
Open
Conversation
When ClaudeX catches an error (e.g. "Claude Code process exited with
code 1"), the error handler now posts two additional file attachments
to the same Slack thread:
- error-stack.txt — the full JavaScript Error stack trace
- service-logs.txt — the last 10 000 lines of the active service log
This makes crashes self-diagnosing directly in Slack without requiring
manual log inspection.
New file: src/util/log-reader.ts
- getLatestLogFile() — finds the newest service_*.log in logs/
- readLastNLines() — reads the last N lines from a file
Modified: src/slack/files.ts
- uploadContentAsFile() — writes a string to a tmp file and uploads
it to Slack, then cleans up the tmp dir
Modified: src/slack/events.ts
- Error handler now calls both helpers after posting the error text
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sets up Vitest (first test infrastructure in the repo) and adds 19 tests covering the two new utilities introduced in the previous commit: src/util/log-reader.test.ts (12 tests) getLatestLogFile: - returns null for empty / missing logs directory - ignores files that don't match service_*.log - returns the single log file when only one exists - returns the most recently modified file among multiple candidates - handles three files and picks the newest readLastNLines: - returns error string for non-existent file - returns full content when file has fewer lines than requested - returns exactly the last N lines - handles empty file, n=1, n=0, and trailing-newline edge cases src/slack/files.test.ts (7 tests) uploadContentAsFile: - calls filesUploadV2 with the correct channel, thread, and filename - verifies the temp file is cleaned up after a successful upload - verifies the temp file is cleaned up even when filesUploadV2 throws - uploads empty string without error - uploads a 10 000-line string (simulating a log tail) without error - preserves the exact filename argument Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When ClaudeX catches an unhandled error (e.g. "Claude Code process exited with code 1"), the thread currently only receives a terse error text message. This PR makes crashes self-diagnosing by attaching two files to the same Slack thread immediately after that message:
error-stack.txt— the full JavaScriptError.stacktrace (or the stringified error if it isn't anErrorinstance)service-logs.txt— the last 10 000 lines of the activelogs/service_*.logfileChanges
src/util/log-reader.ts(new)getLatestLogFile()— locates the newestservice_*.log;readLastNLines()— reads the tail of a filesrc/slack/files.tsuploadContentAsFile()— writes a string to a UUID-named temp file, uploads viafilesUploadV2, then cleans upsrc/slack/events.tstry/catchso a failure to upload diagnostics never hides the original errorTest plan
error-stack.txtappears in the Slack threadservice-logs.txtis also attached and contains recent log lines:x: Sorry, something went wrong: …message still appears first🤖 Generated with Claude Code