refactor: use TypeError
instead of generic Error
when appropriate (#39209)
refactor: use TypeError instead of generic Error when appropriate
This commit is contained in:
parent
77cc1d6ffa
commit
455f57322f
9 changed files with 13 additions and 13 deletions
|
@ -24,12 +24,12 @@ class AutoUpdater extends EventEmitter {
|
||||||
if (typeof options.url === 'string') {
|
if (typeof options.url === 'string') {
|
||||||
updateURL = options.url;
|
updateURL = options.url;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Expected options object to contain a \'url\' string property in setFeedUrl call');
|
throw new TypeError('Expected options object to contain a \'url\' string property in setFeedUrl call');
|
||||||
}
|
}
|
||||||
} else if (typeof options === 'string') {
|
} else if (typeof options === 'string') {
|
||||||
updateURL = options;
|
updateURL = options;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Expected an options object with a \'url\' property to be provided');
|
throw new TypeError('Expected an options object with a \'url\' property to be provided');
|
||||||
}
|
}
|
||||||
this.updateURL = updateURL;
|
this.updateURL = updateURL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,7 +331,7 @@ class TouchBar extends EventEmitter implements Electron.TouchBar {
|
||||||
const idSet = new Set();
|
const idSet = new Set();
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
if (!(item instanceof TouchBarItem)) {
|
if (!(item instanceof TouchBarItem)) {
|
||||||
throw new Error('Each item must be an instance of TouchBarItem');
|
throw new TypeError('Each item must be an instance of TouchBarItem');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === 'other_items_proxy') {
|
if (item.type === 'other_items_proxy') {
|
||||||
|
|
|
@ -34,19 +34,19 @@ class ForkUtilityProcess extends EventEmitter {
|
||||||
|
|
||||||
if (options.execArgv != null) {
|
if (options.execArgv != null) {
|
||||||
if (!Array.isArray(options.execArgv)) {
|
if (!Array.isArray(options.execArgv)) {
|
||||||
throw new Error('execArgv must be an array of strings.');
|
throw new TypeError('execArgv must be an array of strings.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.serviceName != null) {
|
if (options.serviceName != null) {
|
||||||
if (typeof options.serviceName !== 'string') {
|
if (typeof options.serviceName !== 'string') {
|
||||||
throw new Error('serviceName must be a string.');
|
throw new TypeError('serviceName must be a string.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.cwd != null) {
|
if (options.cwd != null) {
|
||||||
if (typeof options.cwd !== 'string') {
|
if (typeof options.cwd !== 'string') {
|
||||||
throw new Error('cwd path must be a string.');
|
throw new TypeError('cwd path must be a string.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ WebContents.prototype.getPrintersAsync = async function () {
|
||||||
|
|
||||||
WebContents.prototype.loadFile = function (filePath, options = {}) {
|
WebContents.prototype.loadFile = function (filePath, options = {}) {
|
||||||
if (typeof filePath !== 'string') {
|
if (typeof filePath !== 'string') {
|
||||||
throw new Error('Must pass filePath as a string');
|
throw new TypeError('Must pass filePath as a string');
|
||||||
}
|
}
|
||||||
const { query, search, hash } = options;
|
const { query, search, hash } = options;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ Object.defineProperty(WebFrameMain.prototype, 'ipc', {
|
||||||
|
|
||||||
WebFrameMain.prototype.send = function (channel, ...args) {
|
WebFrameMain.prototype.send = function (channel, ...args) {
|
||||||
if (typeof channel !== 'string') {
|
if (typeof channel !== 'string') {
|
||||||
throw new Error('Missing required channel argument');
|
throw new TypeError('Missing required channel argument');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -25,7 +25,7 @@ WebFrameMain.prototype.send = function (channel, ...args) {
|
||||||
|
|
||||||
WebFrameMain.prototype._sendInternal = function (channel, ...args) {
|
WebFrameMain.prototype._sendInternal = function (channel, ...args) {
|
||||||
if (typeof channel !== 'string') {
|
if (typeof channel !== 'string') {
|
||||||
throw new Error('Missing required channel argument');
|
throw new TypeError('Missing required channel argument');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class IpcMainImpl extends EventEmitter {
|
||||||
throw new Error(`Attempted to register a second handler for '${method}'`);
|
throw new Error(`Attempted to register a second handler for '${method}'`);
|
||||||
}
|
}
|
||||||
if (typeof fn !== 'function') {
|
if (typeof fn !== 'function') {
|
||||||
throw new Error(`Expected handler to be a function, but found type '${typeof fn}'`);
|
throw new TypeError(`Expected handler to be a function, but found type '${typeof fn}'`);
|
||||||
}
|
}
|
||||||
this._invokeHandlers.set(method, fn);
|
this._invokeHandlers.set(method, fn);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@ export function deregisterEvents (viewInstanceId: number) {
|
||||||
|
|
||||||
export function createGuest (iframe: HTMLIFrameElement, elementInstanceId: number, params: Record<string, any>): Promise<number> {
|
export function createGuest (iframe: HTMLIFrameElement, elementInstanceId: number, params: Record<string, any>): Promise<number> {
|
||||||
if (!(iframe instanceof HTMLIFrameElement)) {
|
if (!(iframe instanceof HTMLIFrameElement)) {
|
||||||
throw new Error('Invalid embedder frame');
|
throw new TypeError('Invalid embedder frame');
|
||||||
}
|
}
|
||||||
|
|
||||||
const embedderFrameId = webFrame.getWebFrameId(iframe.contentWindow!);
|
const embedderFrameId = webFrame.getWebFrameId(iframe.contentWindow!);
|
||||||
|
|
|
@ -18,7 +18,7 @@ const releaseId = parseInt(process.argv[4], 10);
|
||||||
const releaseVersion = process.argv[5];
|
const releaseVersion = process.argv[5];
|
||||||
|
|
||||||
if (isNaN(releaseId)) {
|
if (isNaN(releaseId)) {
|
||||||
throw new Error('Provided release ID was not a valid integer');
|
throw new TypeError('Provided release ID was not a valid integer');
|
||||||
}
|
}
|
||||||
|
|
||||||
const getHeaders = (filePath: string, fileName: string) => {
|
const getHeaders = (filePath: string, fileName: string) => {
|
||||||
|
|
|
@ -477,7 +477,7 @@ WhammyVideo.prototype.add = function (frame, duration) {
|
||||||
// quickly store image data so we don't block cpu. encode in compile method.
|
// quickly store image data so we don't block cpu. encode in compile method.
|
||||||
frame = frame.getContext('2d').getImageData(0, 0, frame.width, frame.height);
|
frame = frame.getContext('2d').getImageData(0, 0, frame.width, frame.height);
|
||||||
} else if (typeof frame !== 'string') {
|
} else if (typeof frame !== 'string') {
|
||||||
throw new Error('frame must be a a HTMLCanvasElement, a CanvasRenderingContext2D or a DataURI formatted string');
|
throw new TypeError('frame must be a a HTMLCanvasElement, a CanvasRenderingContext2D or a DataURI formatted string');
|
||||||
}
|
}
|
||||||
if (typeof frame === 'string' && !(/^data:image\/webp;base64,/ig).test(frame)) {
|
if (typeof frame === 'string' && !(/^data:image\/webp;base64,/ig).test(frame)) {
|
||||||
throw new Error('Input must be formatted properly as a base64 encoded DataURI of type image/webp');
|
throw new Error('Input must be formatted properly as a base64 encoded DataURI of type image/webp');
|
||||||
|
|
Loading…
Add table
Reference in a new issue