diff --git a/lib/browser/api/web-contents.ts b/lib/browser/api/web-contents.ts index bea6d7225d2d..8f0f53aa2ba7 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -211,28 +211,28 @@ WebContents.prototype.printToPDF = async function (options) { if (options.landscape !== undefined) { if (typeof options.landscape !== 'boolean') { - return Promise.reject(new Error('landscape must be a Boolean')); + throw new Error('landscape must be a Boolean'); } printSettings.landscape = options.landscape; } if (options.displayHeaderFooter !== undefined) { if (typeof options.displayHeaderFooter !== 'boolean') { - return Promise.reject(new Error('displayHeaderFooter must be a Boolean')); + throw new Error('displayHeaderFooter must be a Boolean'); } printSettings.displayHeaderFooter = options.displayHeaderFooter; } if (options.printBackground !== undefined) { if (typeof options.printBackground !== 'boolean') { - return Promise.reject(new Error('printBackground must be a Boolean')); + throw new Error('printBackground must be a Boolean'); } printSettings.shouldPrintBackgrounds = options.printBackground; } if (options.scale !== undefined) { if (typeof options.scale !== 'number') { - return Promise.reject(new Error('scale must be a Number')); + throw new Error('scale must be a Number'); } printSettings.scale = options.scale; } @@ -242,53 +242,53 @@ WebContents.prototype.printToPDF = async function (options) { if (typeof pageSize === 'string') { const format = paperFormats[pageSize.toLowerCase()]; if (!format) { - return Promise.reject(new Error(`Invalid pageSize ${pageSize}`)); + throw new Error(`Invalid pageSize ${pageSize}`); } printSettings.paperWidth = format.width; printSettings.paperHeight = format.height; } else if (typeof options.pageSize === 'object') { if (!pageSize.height || !pageSize.width) { - return Promise.reject(new Error('height and width properties are required for pageSize')); + throw new Error('height and width properties are required for pageSize'); } printSettings.paperWidth = pageSize.width; printSettings.paperHeight = pageSize.height; } else { - return Promise.reject(new Error('pageSize must be a String or Object')); + throw new Error('pageSize must be a String or Object'); } } const { margins } = options; if (margins !== undefined) { if (typeof margins !== 'object') { - return Promise.reject(new Error('margins must be an Object')); + throw new Error('margins must be an Object'); } if (margins.top !== undefined) { if (typeof margins.top !== 'number') { - return Promise.reject(new Error('margins.top must be a Number')); + throw new Error('margins.top must be a Number'); } printSettings.marginTop = margins.top; } if (margins.bottom !== undefined) { if (typeof margins.bottom !== 'number') { - return Promise.reject(new Error('margins.bottom must be a Number')); + throw new Error('margins.bottom must be a Number'); } printSettings.marginBottom = margins.bottom; } if (margins.left !== undefined) { if (typeof margins.left !== 'number') { - return Promise.reject(new Error('margins.left must be a Number')); + throw new Error('margins.left must be a Number'); } printSettings.marginLeft = margins.left; } if (margins.right !== undefined) { if (typeof margins.right !== 'number') { - return Promise.reject(new Error('margins.right must be a Number')); + throw new Error('margins.right must be a Number'); } printSettings.marginRight = margins.right; } @@ -296,28 +296,28 @@ WebContents.prototype.printToPDF = async function (options) { if (options.pageRanges !== undefined) { if (typeof options.pageRanges !== 'string') { - return Promise.reject(new Error('pageRanges must be a String')); + throw new Error('pageRanges must be a String'); } printSettings.pageRanges = options.pageRanges; } if (options.headerTemplate !== undefined) { if (typeof options.headerTemplate !== 'string') { - return Promise.reject(new Error('headerTemplate must be a String')); + throw new Error('headerTemplate must be a String'); } printSettings.headerTemplate = options.headerTemplate; } if (options.footerTemplate !== undefined) { if (typeof options.footerTemplate !== 'string') { - return Promise.reject(new Error('footerTemplate must be a String')); + throw new Error('footerTemplate must be a String'); } printSettings.footerTemplate = options.footerTemplate; } if (options.preferCSSPageSize !== undefined) { if (typeof options.preferCSSPageSize !== 'boolean') { - return Promise.reject(new Error('preferCSSPageSize must be a Boolean')); + throw new Error('preferCSSPageSize must be a Boolean'); } printSettings.preferCSSPageSize = options.preferCSSPageSize; } @@ -330,8 +330,7 @@ WebContents.prototype.printToPDF = async function (options) { } return pendingPromise; } else { - const error = new Error('Printing feature is disabled'); - return Promise.reject(error); + throw new Error('Printing feature is disabled'); } }; diff --git a/lib/common/deprecate.ts b/lib/common/deprecate.ts index 94f2e80acd59..c6435cc81603 100644 --- a/lib/common/deprecate.ts +++ b/lib/common/deprecate.ts @@ -46,7 +46,7 @@ export function log (message: string): void { // remove a function with no replacement export function removeFunction (fn: T, removedName: string): T { - if (!fn) { throw Error(`'${removedName} function' is invalid or does not exist.`); } + if (!fn) { throw new Error(`'${removedName} function' is invalid or does not exist.`); } // wrap the deprecated function to warn user const warn = warnOnce(`${fn.name} function`); diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 87b6e616484f..10c931126b7d 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -1422,7 +1422,7 @@ describe('app module', () => { } } else { // return error if not clean exit - return Promise.reject(new Error(errorData)); + throw new Error(errorData); } }; const verifyBasicGPUInfo = async (gpuInfo: any) => {