more strict error type checking in most packages and backend plugins
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
"@backstage/cli-common": "^0.1.4",
|
||||
"@backstage/config": "^0.1.10",
|
||||
"@backstage/config-loader": "^0.6.10",
|
||||
"@backstage/errors": "^0.1.2",
|
||||
"@hot-loader/react-dom": "^16.13.0",
|
||||
"@lerna/package-graph": "^4.0.0",
|
||||
"@lerna/project": "^4.0.0",
|
||||
|
||||
@@ -24,6 +24,7 @@ import camelCase from 'lodash/camelCase';
|
||||
import upperFirst from 'lodash/upperFirst';
|
||||
import os from 'os';
|
||||
import { Command } from 'commander';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import {
|
||||
parseOwnerIds,
|
||||
addCodeownersEntry,
|
||||
@@ -173,6 +174,7 @@ async function buildPlugin(pluginFolder: string) {
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
Task.error(error.message);
|
||||
break;
|
||||
}
|
||||
@@ -329,6 +331,7 @@ export default async (cmd: Command) => {
|
||||
Task.log();
|
||||
Task.exit();
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
Task.error(error.message);
|
||||
|
||||
Task.log('It seems that something went wrong when creating the plugin 🤔');
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { CommanderStatic } from 'commander';
|
||||
import { exitWithError } from '../lib/errors';
|
||||
|
||||
@@ -252,6 +253,7 @@ function lazy(
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
exitWithError(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ import inquirer, { Answers, Question } from 'inquirer';
|
||||
import { getCodeownersFilePath } from '../../lib/codeowners';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { Task } from '../../lib/tasks';
|
||||
import { assertError } from '@backstage/errors';
|
||||
|
||||
const BACKSTAGE = '@backstage';
|
||||
|
||||
@@ -35,6 +36,7 @@ export const checkExists = async (rootDir: string, pluginName: string) => {
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
throw new Error(
|
||||
chalk.red(
|
||||
` There was an error removing plugin ${chalk.cyan(pluginName)}: ${
|
||||
@@ -51,6 +53,7 @@ export const removePluginDirectory = async (destination: string) => {
|
||||
try {
|
||||
await fse.remove(destination);
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
throw Error(
|
||||
chalk.red(
|
||||
` There was a problem removing the plugin directory: ${e.message}`,
|
||||
@@ -67,6 +70,7 @@ export const removeSymLink = async (destination: string) => {
|
||||
try {
|
||||
await fse.remove(destination);
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
throw Error(
|
||||
chalk.red(
|
||||
` Could not remove symbolic link\t${chalk.cyan(destination)}: ${
|
||||
@@ -106,6 +110,7 @@ export const removeReferencesFromPluginsFile = async (
|
||||
try {
|
||||
await removeAllStatementsContainingID(pluginsFile, pluginNameCapitalized);
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
throw new Error(
|
||||
chalk.red(
|
||||
` There was an error removing export statement for plugin ${chalk.cyan(
|
||||
@@ -125,6 +130,7 @@ export const removePluginFromCodeOwners = async (
|
||||
try {
|
||||
await removeAllStatementsContainingID(codeOwnersFile, pluginName);
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
throw new Error(
|
||||
chalk.red(
|
||||
` There was an error removing code owners statement for plugin ${chalk.cyan(
|
||||
@@ -165,6 +171,7 @@ export const removeReferencesFromAppPackage = async (
|
||||
'utf-8',
|
||||
);
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
throw new Error(
|
||||
chalk.red(
|
||||
` Failed to remove plugin as dependency in app: ${chalk.cyan(
|
||||
@@ -245,6 +252,7 @@ export default async () => {
|
||||
);
|
||||
Task.log();
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
Task.error(error.message);
|
||||
Task.log('It seems that something went wrong when removing the plugin 🤔');
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import fs from 'fs-extra';
|
||||
import chalk from 'chalk';
|
||||
import semver from 'semver';
|
||||
import { isError } from '@backstage/errors';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { run } from '../../lib/run';
|
||||
import { paths } from '../../lib/paths';
|
||||
@@ -59,7 +60,7 @@ export default async () => {
|
||||
try {
|
||||
target = await findTargetVersion(name);
|
||||
} catch (error) {
|
||||
if (error.name === 'NotFoundError') {
|
||||
if (isError(error) && error.name === 'NotFoundError') {
|
||||
console.log(`Package info not found, ignoring package ${name}`);
|
||||
return;
|
||||
}
|
||||
@@ -97,7 +98,7 @@ export default async () => {
|
||||
try {
|
||||
target = await findTargetVersion(name);
|
||||
} catch (error) {
|
||||
if (error.name === 'NotFoundError') {
|
||||
if (isError(error) && error.name === 'NotFoundError') {
|
||||
console.log(`Package info not found, ignoring package ${name}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
import { ExitCodeError } from './errors';
|
||||
import { promisify } from 'util';
|
||||
import { LogFunc } from './logging';
|
||||
import { assertError, ForwardedError } from '@backstage/errors';
|
||||
|
||||
const execFile = promisify(execFileCb);
|
||||
|
||||
@@ -75,10 +76,14 @@ export async function runPlain(cmd: string, ...args: string[]) {
|
||||
const { stdout } = await execFile(cmd, args, { shell: true });
|
||||
return stdout.trim();
|
||||
} catch (error) {
|
||||
if (error.stderr) {
|
||||
process.stderr.write(error.stderr);
|
||||
assertError(error);
|
||||
if ('stderr' in error) {
|
||||
process.stderr.write(error.stderr as Buffer);
|
||||
}
|
||||
throw new ExitCodeError(error.code, [cmd, ...args].join(' '));
|
||||
if (typeof error.code === 'number') {
|
||||
throw new ExitCodeError(error.code, [cmd, ...args].join(' '));
|
||||
}
|
||||
throw new ForwardedError('Unknown execution error', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user