Skip to content

Commit

Permalink
feat: log plugin initialisation error on single line (#5684)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas authored May 29, 2024
1 parent 492b2e3 commit 3aecbfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 6 additions & 8 deletions packages/build/src/plugins/system_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ export const captureStandardError = (
}
}

let receivedChunks = false
let buffer = ''

const listener = (chunk: Buffer) => {
if (!receivedChunks) {
receivedChunks = true

systemLog(`Plugin failed to initialize during the "${eventName}" phase`)
}

systemLog(chunk.toString().trimEnd())
buffer += chunk.toString()
}

childProcess.stderr?.on('data', listener)

const cleanup = () => {
childProcess.stderr?.removeListener('data', listener)

if (buffer.length !== 0) {
systemLog(`Plugin failed to initialize during the "${eventName}" phase: ${buffer.trim()}`)
}
}

return cleanup
Expand Down
4 changes: 1 addition & 3 deletions packages/build/tests/plugins/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,8 @@ test('Plugin errors that occur during the loading phase are piped to system logs

if (platform !== 'win32') {
const systemLog = await fs.readFile(systemLogFile.path, { encoding: 'utf8' })
const lines = systemLog.split('\n')

t.is(lines[0].trim(), 'Plugin failed to initialize during the "load" phase')
t.is(lines[1].trim(), 'An error message thrown by Node.js')
t.is(systemLog.trim(), `Plugin failed to initialize during the "load" phase: An error message thrown by Node.js`)
}

t.snapshot(normalizeOutput(output))
Expand Down

0 comments on commit 3aecbfc

Please sign in to comment.