-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat: capture plugin errors during ready
phase
#5681
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { FeatureFlags } from '../core/feature_flags.js' | ||
import type { SystemLogger } from '../plugins_core/types.js' | ||
|
||
import type { ChildProcess } from './spawn.js' | ||
|
||
export const captureStandardError = ( | ||
childProcess: ChildProcess, | ||
systemLog: SystemLogger, | ||
eventName: string, | ||
featureFlags: FeatureFlags, | ||
) => { | ||
if (!featureFlags.netlify_build_plugin_system_log) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I failed to mention this on the last PR, but I think this flag should be called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I totally see that. Let's hope we can kill the flag soon. |
||
return () => { | ||
// no-op | ||
} | ||
} | ||
|
||
let receivedChunks = false | ||
|
||
const listener = (chunk: Buffer) => { | ||
if (!receivedChunks) { | ||
receivedChunks = true | ||
|
||
systemLog(`Plugin failed to initialize during the "${eventName}" phase`) | ||
} | ||
|
||
systemLog(chunk.toString().trimEnd()) | ||
} | ||
|
||
childProcess.stderr?.on('data', listener) | ||
|
||
const cleanup = () => { | ||
childProcess.stderr?.removeListener('data', listener) | ||
} | ||
|
||
return cleanup | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would
setImmediate
also work here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, yes. Just trying to stay as conservative as possible with this change.