Skip to content

Bug: Logger crashes on Windows due to colons in log filenames #42

Description

@mohanad-80

Description

When running the migration utility on Windows, the user migration logic completes successfully, the utility displays an error when attempting to write to the log files on Windows. This is caused by the use of colons (:) in the generated filenames (e.g., migration-2026-02-13T20:45:14.log), which are reserved characters in Windows file systems (NTFS/FAT32).

Error Log

Error writing to log file: 
fs.appendFileSync(fullPath, `${JSON.stringify(entry)}\n`);
^
ENOENT: no such file or directory, open '\\?\D:\Code\Clerk-migration-script\migration-script\logs\migration-2026-02-13T20:45:14.log'
    path: "\\\\?\\D:\\Code\\Clerk-migration-script\\migration-script\\logs\\migration-2026-02-13T20:45:14.log", 
    syscall: "open",
    errno: -2,
    code: "ENOENT"

Steps to Reproduce

  1. Run bun migrate on any Windows terminal (PowerShell, CMD, or Git Bash).
  2. The script successfully processes all users.
  3. The script shows error when appendToLogFile attempts to write any entry to the log file.
  4. No log file is created.

Environment

  • OS: Windows 10/11
  • Runtime: Bun
  • Version: Latest main branch

Proposed Fix

Sanitize the filePath within the appendToLogFile function in src/logger.ts to replace colons with dashes. This ensures cross-platform compatibility regardless of which logger function (error, validation, or import) is called.

File: src/logger.ts

function appendToLogFile(filePath: string, entry: unknown) {
  try {
    const logPath = getLogPath();
    confirmOrCreateFolder(logPath);
    
    // Sanitize file name for Windows compatibility
    filePath = filePath.replace(/:/g, '-'); 
    
    const fullPath = `${logPath}/${filePath}`;

    fs.appendFileSync(fullPath, `${JSON.stringify(entry)}\n`);
  } catch (err) {
    console.error('Error writing to log file:', err);
  }
}

I would be happy to open a Pull Request with this fix if the proposed solution looks good to the team!

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions