Skip to content

Commit

Permalink
Fix errors.json logging empty errors
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Sep 13, 2023
1 parent 4a65a98 commit 924d6cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/sync-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EventEmitter = require('events')
const browserSync = require('browser-sync')
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,8 +20,15 @@ function hasRestartedAfterError () {
}

function flagError (error) {
const errorFormatted = util.inspect(error, {
compact: false,
depth: Infinity,
maxArrayLength: Infinity,
maxStringLength: Infinity
})

ensureDirSync(path.dirname(errorsFile))
writeJsonSync(errorsFile, { error })
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

0 comments on commit 924d6cb

Please sign in to comment.