Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors.json logging ENOENT: no such file or directory #2332

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/sync-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const EventEmitter = require('events')

// npm dependencies
const browserSync = require('browser-sync')
const { writeJsonSync } = require('fs-extra')
const { ensureDirSync, writeJsonSync } = require('fs-extra')
const path = require('path')
const util = require('util')
const { tmpDir } = require('./utils/paths')
const fs = require('fs')

Expand All @@ -19,7 +20,15 @@ function hasRestartedAfterError () {
}

function flagError (error) {
writeJsonSync(path.join(tmpDir, 'errors.json'), { error })
const errorFormatted = util.inspect(error, {
compact: false,
depth: Infinity,
maxArrayLength: Infinity,
maxStringLength: Infinity
})

ensureDirSync(path.dirname(errorsFile))
writeJsonSync(errorsFile, { error: errorFormatted })
}

function unflagError () {
Expand Down
3 changes: 2 additions & 1 deletion lib/sync-changes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ describe('sync-changes', () => {

it('flags error correctly', () => {
const error = { data: true }
const errorFormatted = '{\n data: true\n}'

syncChanges.flagError(error)

expect(fse.writeJsonSync).toHaveBeenCalledTimes(1)
expect(fse.writeJsonSync).toHaveBeenCalledWith(errorsFile, { error })
expect(fse.writeJsonSync).toHaveBeenCalledWith(errorsFile, { error: errorFormatted })
})

it('syncs correctly', () => {
Expand Down