diff --git a/.eslintrc.js b/.eslintrc.js index 60103e9da..ce8065678 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -70,6 +70,10 @@ module.exports = { 'no-var': ['error'], 'no-new-func': ['error'], 'import/prefer-default-export': ['error'], + 'prefer-promise-reject-errors': ['error', { + allowEmptyReject: true, + }], + 'no-throw-literal': ['error'], // This rule should not be enabled since it matters in what order // imports are done, in particular in relation to the shim.setReact diff --git a/packages/app-desktop/generateSha512.js b/packages/app-desktop/generateSha512.js index 900580948..17f3748ae 100644 --- a/packages/app-desktop/generateSha512.js +++ b/packages/app-desktop/generateSha512.js @@ -19,7 +19,7 @@ const generateChecksumFile = () => { } } if (appImageName === '') { - throw 'AppImage not found!'; + throw new Error('AppImage not found!'); } const appImagePath = path.join(distPath, appImageName); const appImageContent = fs.readFileSync(appImagePath); diff --git a/packages/app-mobile/components/NoteEditor/ImageEditor/js-draw/createJsDrawEditor.ts b/packages/app-mobile/components/NoteEditor/ImageEditor/js-draw/createJsDrawEditor.ts index 80635cf89..396d80b1d 100644 --- a/packages/app-mobile/components/NoteEditor/ImageEditor/js-draw/createJsDrawEditor.ts +++ b/packages/app-mobile/components/NoteEditor/ImageEditor/js-draw/createJsDrawEditor.ts @@ -133,7 +133,7 @@ export const createJsDrawEditor = ( const request = new XMLHttpRequest(); const onError = () => { - reject(`Failed to load initial SVG data: ${request.status}, ${request.statusText}, ${request.responseText}`); + reject(new Error(`Failed to load initial SVG data: ${request.status}, ${request.statusText}, ${request.responseText}`)); }; request.addEventListener('load', _ => { diff --git a/packages/app-mobile/components/getResponsiveValue.ts b/packages/app-mobile/components/getResponsiveValue.ts index 5a82307bb..fe2ecbbdb 100644 --- a/packages/app-mobile/components/getResponsiveValue.ts +++ b/packages/app-mobile/components/getResponsiveValue.ts @@ -30,7 +30,7 @@ export interface ValueMap { export default function getResponsiveValue(valueMap: ValueMap): number { if (Object.keys(valueMap).length === 0) { - throw 'valueMap cannot be an empty object!'; + throw new Error('valueMap cannot be an empty object!'); } const width = Dimensions.get('window').width; diff --git a/packages/lib/file-api-driver-amazon-s3.js b/packages/lib/file-api-driver-amazon-s3.js index ec54664a1..90481d8ae 100644 --- a/packages/lib/file-api-driver-amazon-s3.js +++ b/packages/lib/file-api-driver-amazon-s3.js @@ -252,6 +252,7 @@ class FileApiDriverAmazonS3 { output = await response.text(); // we need to make sure that errors get thrown as we are manually fetching above. if (!response.ok) { + // eslint-disable-next-line no-throw-literal -- Old code before rule was applied throw { name: response.statusText, output: output }; } } diff --git a/packages/lib/shim-init-node.ts b/packages/lib/shim-init-node.ts index 9f4afa842..8b0a9ab24 100644 --- a/packages/lib/shim-init-node.ts +++ b/packages/lib/shim-init-node.ts @@ -228,8 +228,8 @@ function shimInit(options: ShimInitOptions = null) { image.src = filePath; await new Promise((resolve, reject) => { image.onload = () => resolve(); - image.onerror = () => reject(`Image at ${filePath} failed to load.`); - image.onabort = () => reject(`Loading stopped for image at ${filePath}.`); + image.onerror = () => reject(new Error(`Image at ${filePath} failed to load.`)); + image.onabort = () => reject(new Error(`Loading stopped for image at ${filePath}.`)); }); if (!image.complete || (image.width === 0 && image.height === 0)) { throw new Error(`Image is invalid or does not exist: ${filePath}`); diff --git a/packages/tools/tool-utils.ts b/packages/tools/tool-utils.ts index 09e137768..da5aee029 100644 --- a/packages/tools/tool-utils.ts +++ b/packages/tools/tool-utils.ts @@ -164,7 +164,7 @@ export function execCommandWithPipes(executable: string, args: string[]) { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied child.on('close', (code: any) => { if (code !== 0) { - reject(`Ended with code ${code}`); + reject(new Error(`Ended with code ${code}`)); } else { resolve(null); }