mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-22 14:01:31 -05:00
Add error codes to our custom errors (#959)
This commit is contained in:
@@ -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]));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user