Add error codes to our custom errors (#959)

This commit is contained in:
Fábio Rosado
2022-11-25 17:04:10 +00:00
committed by GitHub
parent 30e31a86ef
commit b062efcf17
20 changed files with 306 additions and 67 deletions

View File

@@ -1,6 +1,6 @@
import { joinPaths } from '../utils';
import { FetchConfig } from "../pyconfig";
import { UserError } from '../exceptions';
import { UserError, ErrorCode } from '../exceptions';
export function calculatePaths(fetch_cfg: FetchConfig[]) {
const fetchPaths: string[] = [];
@@ -14,7 +14,10 @@ export function calculatePaths(fetch_cfg: FetchConfig[]) {
{
if (to_file !== undefined)
{
throw new UserError(`Cannot use 'to_file' and 'files' parameters together!`);
throw new UserError(
ErrorCode.BAD_CONFIG,
`Cannot use 'to_file' and 'files' parameters together!`
);
}
for (const each_f of files)
{
@@ -29,7 +32,10 @@ export function calculatePaths(fetch_cfg: FetchConfig[]) {
fetchPaths.push(from);
const filename = to_file || from.split('/').pop();
if (filename === '') {
throw new UserError(`Couldn't determine the filename from the path ${from}, supply ${to_file} parameter!`);
throw new UserError(
ErrorCode.BAD_CONFIG,
`Couldn't determine the filename from the path ${from}, please supply 'to_file' parameter.`
);
}
else {
paths.push(joinPaths([to_folder, filename]));

View File

@@ -2,7 +2,7 @@ import type { PyScriptApp } from '../main';
import type { AppConfig } from '../pyconfig';
import type { Runtime } from '../runtime';
import { Plugin } from '../plugin';
import { UserError } from "../exceptions"
import { UserError, ErrorCode } from "../exceptions"
import { getLogger } from '../logger';
import { type Stdio } from '../stdio';
@@ -24,8 +24,11 @@ export class PyTerminalPlugin extends Plugin {
t !== false &&
t !== "auto") {
const got = JSON.stringify(t);
throw new UserError('Invalid value for config.terminal: the only accepted' +
`values are true, false and "auto", got "${got}".`);
throw new UserError(
ErrorCode.BAD_CONFIG,
'Invalid value for config.terminal: the only accepted' +
`values are true, false and "auto", got "${got}".`
);
}
if (t === undefined) {
config.terminal = "auto"; // default value