Skip to content

Commit

Permalink
Merge pull request #787 from peppergrayxyz/png2src_report_error
Browse files Browse the repository at this point in the history
return png2src error to caller
  • Loading branch information
aduros authored Dec 13, 2024
2 parents f5acbb3 + eb2f35f commit 363d122
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ program.command("png2src <images...>")
if (!opts.template) {
opts.lang = requireLang(opts);
}
png2src.runAll(images, opts);
try {
png2src.runAll(images, opts);
} catch (error) {
console.error(error.message);
process.exit(1);
}
});

program.command("bundle <cart>")
Expand Down
3 changes: 1 addition & 2 deletions cli/lib/png2src.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ function runAll(files, opts) {

output.sprites.push(run(file));
} catch (error) {
console.error("Error processing " + file + ": " + error.message);
break;
throw new Error("Error processing " + file + ": " + error.message);
}
}

Expand Down
6 changes: 3 additions & 3 deletions cli/lib/test/png2src.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ describe("PNG2SRC", () => {
});

it("should abort and output an error message for invalid image paths", () => {
runAll(["/invalid/path"], {
expect(() =>
runAll(["/invalid/path"], {
lang: "rust",
output: "-",
});
expect(console.error).toHaveBeenCalledWith("Error processing /invalid/path: ENOENT: no such file or directory, open '/invalid/path'");
})).toThrowError(/Error processing \/invalid\/path: ENOENT: no such file or directory, open '\/invalid\/path'/);
});

it("should console log one sprite", () => {
Expand Down

0 comments on commit 363d122

Please sign in to comment.