-
Notifications
You must be signed in to change notification settings - Fork 4
SED-4789 Implement live reporting in the Node.js agent #661
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ node_modules/ | |
| filemanager/work/ | ||
| /coverage/ | ||
| /npm-project-workspaces/ | ||
| /agent-fork-libs/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| */ | ||
|
|
||
| const { OutputBuilder } = require("./output"); | ||
| const { createLiveReporting } = require("./live-reporting"); | ||
| const Session = require("./session"); | ||
| const fs = require("fs"); | ||
| const path = require('path') | ||
|
|
@@ -34,7 +35,11 @@ process.on('message', async ({ type, projectPath, functionName, input, propertie | |
| pendingUncaughtException = null; | ||
| console.log("[Agent fork] Calling keyword " + functionName) | ||
| const outputBuilder = new OutputBuilder(); | ||
| let liveReporting; | ||
| try { | ||
| // Initialize inside the try so any initialization error is reported via outputBuilder.fail | ||
| // (in the catch below) rather than escaping the message handler. | ||
| liveReporting = createLiveReporting(properties); | ||
| if (!keywordDirectoryExists(projectPath, keywordDirectory)) { | ||
| outputBuilder.fail("The keyword directory '" + keywordDirectory + "' doesn't exist in " + path.basename(projectPath) + ". Possible cause: If using TypeScript, the keywords may not have been compiled. Fix: Ensure your project is built before deploying to Step or during 'npm install'.") | ||
| } else { | ||
|
|
@@ -52,7 +57,7 @@ process.on('message', async ({ type, projectPath, functionName, input, propertie | |
| if(beforeKeyword) { | ||
| await beforeKeyword(functionName); | ||
| } | ||
| await keyword(input, outputBuilder, session, properties); | ||
| await keyword(input, outputBuilder, session, properties, liveReporting); | ||
| } catch (e) { | ||
| console.log("[Agent fork] Keyword execution failed with following error", e) | ||
| const onError = module['onError']; | ||
|
|
@@ -82,6 +87,15 @@ process.on('message', async ({ type, projectPath, functionName, input, propertie | |
| // Flush the event loop so unhandledRejection / uncaughtException from the keyword | ||
| // (e.g. fire-and-forget promises, nextTick throws) land before we send the result. | ||
| await new Promise(resolve => setImmediate(resolve)); | ||
| // Close live reporting: flushes any buffered measures and waits for in-flight uploads. | ||
| // Guarded because initialization above may have failed before liveReporting was assigned. | ||
| try { | ||
| if (liveReporting) { | ||
| await liveReporting.close(); | ||
| } | ||
| } catch (e) { | ||
| console.log("[Agent fork] Error while closing live reporting", e); | ||
| } | ||
|
Comment on lines
+92
to
+98
Contributor
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. Add a safety check to ensure try {
if (liveReporting) {
await liveReporting.close();
}
} catch (e) {
console.log("[Agent fork] Error while closing live reporting", e);
}References
Contributor
Author
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. Done — added the |
||
| // Surface inter-keyword errors first, labelled clearly as coming from a previous keyword. | ||
| if (prevUnhandledRejection) { | ||
| const sep = outputBuilder.hasError() ? '\n' : ''; | ||
|
|
||
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.
To prevent any unexpected errors during
createLiveReportinginitialization from crashing the fork process, declareliveReportingusingletand initialize it inside thetryblock. This ensures any initialization errors are caught and reported gracefully viaoutputBuilder.fail.Uh oh!
There was an error while loading. Please reload this page.
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.
Done —
liveReportingis now declared withletand initialized as the first statement inside thetry, so any initialization error is reported viaoutputBuilder.failinstead of escaping the message handler.