Skip to content

Commit

Permalink
breaking(runtime): remove $.throwErrors (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar authored Jul 11, 2022
1 parent 5a8a218 commit 0fc54c8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,9 @@ notes.
- **$.verbose:** Enable debugging output (log shell commands and execution
time).
- **$.stdout:** Change stdout mode of `` $`command` ``. Can be `"inherit"`,
`"piped"`, `"null"` or `number`. Will be reverted to default after all async
ops are done. Default: `"piped"`
`"piped"`, `"null"` or `number`. Default: `"piped"`
- **$.stderr:** Change stderr mode of `` $`command` ``. Can be `"inherit"`,
`"piped"`, `"null"` or `number`. Will be reverted to default after all async
ops are done. Default: `"piped"`
- **$.throwErrors:** Throw errors instead of calling `Deno.exit`.
`"piped"`, `"null"` or `number`. Default: `"piped"`
- **$.args:** Equivalent to `Deno.args`, but without the script name as first
argument.
- **$.startTime:** The execution start time in ms.
Expand Down
15 changes: 2 additions & 13 deletions src/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { colors, path } from "./runtime/deps.ts";
import { $ } from "./runtime/shell.ts";

export function error(message: string | Error, exitCode = 1): Error {
if ($.throwErrors) {
return (message instanceof Error
? message
: new Error(getErrorMessage(message)));
}
console.error(message instanceof Error ? message : getErrorMessage(message));
Deno.exit(exitCode);
}

function getErrorMessage(message: string) {
return colors.red(`${colors.bold("error:")} ${message}`);
export function error(message: string | Error): Error {
return (message instanceof Error ? message : new Error(colors.red(message)));
}

export function addProtocol(script: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function repl(
"repl",
"--unstable", // dzx requires unstable
"--eval",
`${runtime}\n$.throwErrors = true;\nconsole.log("dzx ${VERSION}");`,
`${runtime}\nconsole.log("dzx ${VERSION}");`,
];

const flags = generateFlags({
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type $ = typeof exec & typeof colors & {
stdout: NonNullable<Deno.RunOptions["stdout"]>;
stderr: NonNullable<Deno.RunOptions["stderr"]>;
quote: typeof shq;
throwErrors: boolean;
time: number;
};

Expand All @@ -30,7 +29,6 @@ $.stdin = "inherit";
$.stdout = "piped";
$.stderr = "piped";
$.quote = shq;
$.throwErrors = false;

let _verbose = 1;
Object.defineProperty($, "verbose", {
Expand Down

0 comments on commit 0fc54c8

Please sign in to comment.