From eb2f35f1d58ce8c90fa3ec17fb4b9525539d73d4 Mon Sep 17 00:00:00 2001 From: Pepper Gray <111446242+peppergrayxyz@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:17:58 +0100 Subject: [PATCH] return png2src error to caller --- cli/cli.js | 7 ++++++- cli/lib/png2src.js | 3 +-- cli/lib/test/png2src.test.js | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cli/cli.js b/cli/cli.js index 7cb9edb8..70a74740 100755 --- a/cli/cli.js +++ b/cli/cli.js @@ -173,7 +173,12 @@ program.command("png2src ") 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 ") diff --git a/cli/lib/png2src.js b/cli/lib/png2src.js index 4d8dd445..1553394a 100644 --- a/cli/lib/png2src.js +++ b/cli/lib/png2src.js @@ -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); } } diff --git a/cli/lib/test/png2src.test.js b/cli/lib/test/png2src.test.js index dc946264..a97ac492 100644 --- a/cli/lib/test/png2src.test.js +++ b/cli/lib/test/png2src.test.js @@ -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", () => {