Skip to content

app Handle missing log files gracefully on first launch#1508

Open
DSingh0304 wants to merge 1 commit intozulip:mainfrom
DSingh0304:fix-excessive-logging
Open

app Handle missing log files gracefully on first launch#1508
DSingh0304 wants to merge 1 commit intozulip:mainfrom
DSingh0304:fix-excessive-logging

Conversation

@DSingh0304
Copy link
Copy Markdown
Collaborator

Fixes: #1281

Description

This PR resolves an issue where the application floods the terminal with UnhandledPromiseRejectionWarning: ENOENT errors during its first launch (fresh install).

Root Cause: The Logger constructor in app/common/logger-util.ts schedules a log-trimming operation (trimLog) to run via process.nextTick. On a fresh install, this operation frequently attempts to read log files before the application's write stream has physically created them on disk, leading to multiple "File not found" errors in the terminal.

Technical Changes

  1. Resilient Log Trimming: Added a try/catch block around the fs.promises.readFile operation in app/common/logger-util.ts.
  2. Graceful Fallback: If a log file does not exist yet (expected on a fresh install), the trimmer now returns early and silently. This ensures a clean and professional first-launch experience without extraneous unhandled rejection warnings.

Screenshots and screen captures:
Screenshot from 2026-03-28 12-59-59

Platforms this PR was tested on:

  • Windows
  • macOS
  • Linux (Ubuntu 24.04)
Self-review checklist
  • Self-reviewed the changes for clarity and maintainability.
  • Each commit is a coherent idea and follows Zulip's commit discipline.
  • Commit message(s) explain reasoning and motivation for changes.
  • Terminal output verified for a clean startup on a fresh install (simulated via rm -rf ~/.config/Zulip).
  • Logic handles corner cases (missing files, unreadable files) gracefully.

On a fresh install, the Logger constructor schedules trimLog() via
process.nextTick before the write stream has created the log file.
This causes an unhandled ENOENT promise rejection for every logger
instance, flooding the terminal with confusing error messages.

Add a try catch around the file read in trimLog() so that missing
files are silently skipped. If the file does not exist yet, there
is nothing to trim.

Fixes zulip#1281.
@DSingh0304
Copy link
Copy Markdown
Collaborator Author

Ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Excessive error logging on first install

1 participant