@@ -6,13 +6,11 @@ import { ANAL_CHARACTERS } from './constants.js';
66
77export 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
3028export 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