Skip to content

Commit 6eb471b

Browse files
committed
chore(stdlib): replace exit with throw
Signed-off-by: mateonunez <mateonunez95@gmail.com>
1 parent 83a650c commit 6eb471b

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

lib/stdlib.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import { ANAL_CHARACTERS } from './constants.js';
66

77
export function anallify(string) {
88
if (!checker(string)) {
9-
process.stderr.write(`${ERROR.notString}\n`);
10-
return process.exit(1);
9+
throw new Error(ERROR.notString);
1110
}
1211

1312
if (!string) {
14-
process.stderr.write(`${ERROR.missingArgument}\n`);
15-
return process.exit(1);
13+
throw new Error(ERROR.missingArgument);
1614
}
1715

1816
let anal = '';
@@ -29,13 +27,11 @@ export function anallify(string) {
2927

3028
export function stringify(anal) {
3129
if (!checker(anal)) {
32-
process.stderr.write(`${ERROR.notString}\n`);
33-
return process.exit(1);
30+
throw new Error(ERROR.notString);
3431
}
3532

3633
if (!anal) {
37-
process.stderr.write(`${ERROR.missingArgument}\n`);
38-
return process.exit(1);
34+
throw new Error(ERROR.missingArgument);
3935
}
4036

4137
let string = '';
@@ -56,8 +52,7 @@ export function run(file) {
5652
const contents = fs.readFileSync(file, { encoding: 'utf-8' });
5753
return stringify(contents);
5854
} catch (error) {
59-
process.stderr.write(`${ERROR.fileNotFound}\n`);
60-
return process.exit(1);
55+
throw new Error(ERROR.fileNotFound);
6156
}
6257
}
6358

@@ -72,7 +67,6 @@ export function compile(file) {
7267
fs.writeFileSync(`${filename}.anal`, anallify(contents), { encoding: 'utf-8' });
7368
process.stdout.write(`${SUCCESS.compileSuccess}`);
7469
} catch (error) {
75-
process.stderr.write(`${ERROR.fileNotFound}\n`);
76-
process.exit(1);
70+
throw new Error(ERROR.fileNotFound);
7771
}
7872
}

0 commit comments

Comments
 (0)