From 6eca885edc1e48572e85397598189d60ad40ebed Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Wed, 13 Sep 2023 15:51:23 +0100 Subject: [PATCH] Fix errors.json logging empty errors --- lib/sync-changes.js | 10 +++++++++- lib/sync-changes.test.js | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/sync-changes.js b/lib/sync-changes.js index 626a1978c1..4227e4afd7 100644 --- a/lib/sync-changes.js +++ b/lib/sync-changes.js @@ -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') @@ -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 () { diff --git a/lib/sync-changes.test.js b/lib/sync-changes.test.js index 3974f55901..41ac396a02 100644 --- a/lib/sync-changes.test.js +++ b/lib/sync-changes.test.js @@ -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') @@ -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', () => {