Skip to content

Commit

Permalink
chore: add try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
rosnovsky committed Feb 5, 2024
1 parent b8eeeba commit ad5e029
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import fs from "node:fs";
import path from "node:path";
import { mdToPdf } from "md-to-pdf";

const markdownFilePath = "./resume.md";
const outputFilePath = "output/art_rosnovsky_software_engineer.pdf";

(async () => {
const pdf = await mdToPdf({ path: "./resume.md" }).catch(console.error);
if (!fs.existsSync(markdownFilePath)) {
console.error(`File ${markdownFilePath} does not exist.`);
throw new Error(`File ${markdownFilePath} does not exist.`);
}

try {
const pdf = await mdToPdf({ path: markdownFilePath });

if (pdf) {
fs.writeFileSync("output/art_rosnovsky_software_engineer.pdf", pdf.content);
if (pdf) {
fs.writeFileSync(path.resolve(__dirname, outputFilePath), pdf.content);
console.log(`PDF has been written to ${outputFilePath}`);
}
} catch (error: any) {
console.error(`Error occurred: ${error.message}`);
throw new Error(error.message);
}
})();
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "resume-manager",
"version": "1.0.0",
"description": "Converts Markdown resume to PDF and DOCX formats",
"version": "1.0.1",
"description": "Converts Markdown resume to PDF format.",
"main": "dist/index.js",
"scripts": {
"build": "ts-node index.ts"
Expand Down

0 comments on commit ad5e029

Please sign in to comment.