Skip to content

Commit 94fb214

Browse files
committed
feat: get rid of the --debug flag
BREAKING CHANGE: The `--debug` flag has been removed. All errors are printed instead, in the hopes that giving the user every hint possible will help them get down to the root of their problem. Hopefully the error stacks don't confuse anyone. 🤓 Closes #54.
1 parent ca9fe3d commit 94fb214

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Options:
7171
--as-html ................ Output as HTML instead
7272
--config-file ............ Path to a JSON or JS configuration file
7373
--devtools ............... Open the browser with devtools instead of creating PDF
74-
--debug .................. Show more output on errors
7574
```
7675

7776
The pdf is generated into the same directory as the source file and uses the same filename (with `.pdf` extension) by default. Multiple files can be specified by using shell globbing, e. g.:

src/cli.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const cliFlags = arg({
3939
'--as-html': Boolean,
4040
'--config-file': String,
4141
'--devtools': Boolean,
42-
'--debug': Boolean,
4342

4443
// aliases
4544
'-h': '--help',
@@ -96,12 +95,7 @@ async function main(args: typeof cliFlags, config: Config) {
9695
};
9796
} catch (error) {
9897
console.warn(chalk.red(`Warning: couldn't read config file: ${path.resolve(args['--config-file'])}`));
99-
100-
if (args['--debug']) {
101-
console.error(error);
102-
} else if (error instanceof SyntaxError) {
103-
console.error(error.message);
104-
}
98+
console.warn(error instanceof SyntaxError ? error.message : error);
10599
}
106100
}
107101

@@ -122,14 +116,13 @@ async function main(args: typeof cliFlags, config: Config) {
122116
*/
123117

124118
if (stdin) {
125-
await convertMdToPdf({ content: stdin }, config, args).catch(async (error: Error) => {
126-
await closeServer(server);
127-
128-
console.error(error);
129-
process.exit(1);
130-
});
119+
await convertMdToPdf({ content: stdin }, config, args)
120+
.then(async () => closeServer(server))
121+
.catch(async (error: Error) => {
122+
await closeServer(server);
131123

132-
await closeServer(server);
124+
throw error;
125+
});
133126

134127
return;
135128
}
@@ -145,12 +138,23 @@ async function main(args: typeof cliFlags, config: Config) {
145138
if (args['--watch']) {
146139
console.log(chalk.bgBlue('\n watching for changes \n'));
147140

148-
watch(files).on('change', async file => {
149-
await new Listr([getListrTask(file)]).run().catch((error: Error) => args['--debug'] && console.error(error));
150-
});
141+
watch(files).on('change', async file =>
142+
new Listr([getListrTask(file)], { exitOnError: false }).run().catch(console.error),
143+
);
151144
} else {
152145
server.close();
153146
}
154147
})
155-
.catch((error: Error) => (args['--debug'] && console.error(error)) || process.exit(1));
148+
.catch((error: Error) => {
149+
/**
150+
* In watch mode the error needs to be shown immediately because the `main` function's catch handler will never execute.
151+
*
152+
* @todo is this correct or does `main` actually finish and the process is just kept alive because of the file server?
153+
*/
154+
if (args['--watch']) {
155+
return console.error(error);
156+
}
157+
158+
throw error;
159+
});
156160
}

src/lib/help.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const helpText = `
2222
--as-html ${chalk.dim('................')} Output as HTML instead
2323
--config-file ${chalk.dim('............')} Path to a JSON or JS configuration file
2424
--devtools ${chalk.dim('...............')} Open the browser with devtools instead of creating PDF
25-
--debug ${chalk.dim('..................')} Show more output on errors
2625
2726
${chalk.dim.underline.bold('Examples:')}
2827

0 commit comments

Comments
 (0)