Skip to content

Commit

Permalink
Defer loading the 'serialised-error' module
Browse files Browse the repository at this point in the history
The 'serialised-error' module is only required when there is an error,
so this change improves the loading time of this module by loading it
only when it is needed for error processing.

Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Nov 20, 2024
1 parent 24d6dc7 commit 8496201
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/runner/extensions/event.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var _ = require('lodash'),
util = require('../util'),
sdk = require('postman-collection'),
sandbox = require('postman-sandbox'),
serialisedError = require('serialised-error'),
ToughCookie = require('@postman/tough-cookie').Cookie,

createItemContext = require('../create-item-context'),
Expand Down Expand Up @@ -44,7 +43,11 @@ postProcessContext = function (execution, failures) { // function determines whe
error.name = ASSERTION_FAILURE;
}

return error ? serialisedError(error, true) : undefined;
if (!error) {
return undefined;
}
const serialisedError = require('serialised-error');
return serialisedError(error, true);

Check failure on line 50 in lib/runner/extensions/event.command.js

View workflow job for this annotation

GitHub Actions / Lint

Expected blank line before this statement
};

/**
Expand Down Expand Up @@ -472,6 +475,7 @@ module.exports = {
// instance once it is fully supported
result && { cookies: result.cookies });
}).catch(function (err) {
const serialisedError = require('serialised-error');
const error = serialisedError(err);

Check failure on line 479 in lib/runner/extensions/event.command.js

View workflow job for this annotation

GitHub Actions / Lint

Combine this with the previous 'const' statement

delete error.stack; // remove stack to avoid leaking runtime internals
Expand Down Expand Up @@ -522,7 +526,10 @@ module.exports = {
}

// electron IPC does not bubble errors to the browser process, so we serialize it here.
err && (err = serialisedError(err, true));
if (err) {
const serialisedError = require('serialised-error');
err = serialisedError(err, true);

Check failure on line 531 in lib/runner/extensions/event.command.js

View workflow job for this annotation

GitHub Actions / Lint

Expected blank line before this statement
}

// if it is defined that certain variables are to be synced back to result, we do the same
track && result && track.forEach(function (variable) {
Expand Down

0 comments on commit 8496201

Please sign in to comment.