Skip to content

Commit

Permalink
feat: get rid of the --debug flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
simonhaenisch committed Jan 26, 2020
1 parent ca9fe3d commit 94fb214
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Options:
--as-html ................ Output as HTML instead
--config-file ............ Path to a JSON or JS configuration file
--devtools ............... Open the browser with devtools instead of creating PDF
--debug .................. Show more output on errors
```

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.:
Expand Down
40 changes: 22 additions & 18 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const cliFlags = arg({
'--as-html': Boolean,
'--config-file': String,
'--devtools': Boolean,
'--debug': Boolean,

// aliases
'-h': '--help',
Expand Down Expand Up @@ -96,12 +95,7 @@ async function main(args: typeof cliFlags, config: Config) {
};
} catch (error) {
console.warn(chalk.red(`Warning: couldn't read config file: ${path.resolve(args['--config-file'])}`));

if (args['--debug']) {
console.error(error);
} else if (error instanceof SyntaxError) {
console.error(error.message);
}
console.warn(error instanceof SyntaxError ? error.message : error);
}
}

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

if (stdin) {
await convertMdToPdf({ content: stdin }, config, args).catch(async (error: Error) => {
await closeServer(server);

console.error(error);
process.exit(1);
});
await convertMdToPdf({ content: stdin }, config, args)
.then(async () => closeServer(server))
.catch(async (error: Error) => {
await closeServer(server);

await closeServer(server);
throw error;
});

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

watch(files).on('change', async file => {
await new Listr([getListrTask(file)]).run().catch((error: Error) => args['--debug'] && console.error(error));
});
watch(files).on('change', async file =>
new Listr([getListrTask(file)], { exitOnError: false }).run().catch(console.error),
);
} else {
server.close();
}
})
.catch((error: Error) => (args['--debug'] && console.error(error)) || process.exit(1));
.catch((error: Error) => {
/**
* In watch mode the error needs to be shown immediately because the `main` function's catch handler will never execute.
*
* @todo is this correct or does `main` actually finish and the process is just kept alive because of the file server?
*/
if (args['--watch']) {
return console.error(error);
}

throw error;
});
}
1 change: 0 additions & 1 deletion src/lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const helpText = `
--as-html ${chalk.dim('................')} Output as HTML instead
--config-file ${chalk.dim('............')} Path to a JSON or JS configuration file
--devtools ${chalk.dim('...............')} Open the browser with devtools instead of creating PDF
--debug ${chalk.dim('..................')} Show more output on errors
${chalk.dim.underline.bold('Examples:')}
Expand Down

0 comments on commit 94fb214

Please sign in to comment.