From 69c2815d5a4b28efce938a89a9d89e58b0debd3c Mon Sep 17 00:00:00 2001 From: David Chandler Date: Tue, 9 Apr 2019 17:55:52 +0100 Subject: [PATCH] fix: propagate errors that occur when parsing less imports. Fixes #30. --- src/import-buffer.ts | 9 ++------- test/import-buffer.js | 22 +++++----------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/import-buffer.ts b/src/import-buffer.ts index 209fec5..9a6a54c 100644 --- a/src/import-buffer.ts +++ b/src/import-buffer.ts @@ -42,13 +42,8 @@ export class ImportBuffer { public async listImports(file: File): Promise { const useImportLister: () => Promise = async () => { - try { - const importListerResults = await this.importLister(file); - return await this.cacheResults(file.path, importListerResults); - } catch (error) { - console.error(`An unknown error occurred: ${error}`); - return []; - } + const importListerResults = await this.importLister(file); + return this.cacheResults(file.path, importListerResults); }; const existingImports = await this.loadPreviousResults(file.path); diff --git a/test/import-buffer.js b/test/import-buffer.js index 8cebaef..810f830 100644 --- a/test/import-buffer.js +++ b/test/import-buffer.js @@ -357,25 +357,12 @@ describe("import-buffer", () => { ]); }); - it("should return no imports if unknown error occurs", async () => { + it("should propagate error if unknown error occurs", async () => { var fakeError = new Error("test"); fakeError.code = "SOMEERR"; spyContext.stub(fsStub, "stat").throws(fakeError); - const imports = await buffer.listImports(mainFile); - expect(imports).to.be.empty; - }); - - it("should log error if unknown error occurs", async () => { - const fakeError = new Error("test"); - fakeError.code = "SOMEERR"; - spyContext.stub(fsStub, "stat").throws(fakeError); - spyContext.spy(console, "error"); - - await buffer.listImports(mainFile); - expect(console.error).to.have.been.calledWith( - "An unknown error occurred: Error: test" - ); + await expect(buffer.listImports(mainFile)).to.eventually.be.rejectedWith(Error, "test"); }); it("should not cache results if unknown error occurs", async () => { @@ -385,10 +372,11 @@ describe("import-buffer", () => { newSpyContext.stub(fsStub, "stat").throws(fakeError); newSpyContext.spy(console, "error"); - let imports = await buffer.listImports(mainFile); + await expect(buffer.listImports(mainFile)).to.eventually.be.rejectedWith(); + newSpyContext.restore(); - imports = await buffer.listImports(mainFile); + const imports = await buffer.listImports(mainFile); expect(imports).not.to.be.empty; }); });