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 6eca885
Show file tree
Hide file tree
Showing 2 changed files with 12 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
4 changes: 3 additions & 1 deletion lib/sync-changes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fs = require('fs')
const fse = require('fs-extra')
const browserSync = require('browser-sync')
const path = require('path')
const util = require('util')
const { tmpDir } = require('./utils/paths')

const errorsFile = path.join(tmpDir, 'errors.json')
Expand All @@ -23,11 +24,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 6eca885

Please sign in to comment.