Skip to content

Commit

Permalink
fix: propagate errors that occur when parsing less imports.
Browse files Browse the repository at this point in the history
Fixes #30.
  • Loading branch information
bingnz committed Apr 9, 2019
1 parent 11ac4b9 commit 69c2815
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
9 changes: 2 additions & 7 deletions src/import-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ export class ImportBuffer {

public async listImports(file: File): Promise<IFileInfo[]> {
const useImportLister: () => Promise<IFileInfo[]> = 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);
Expand Down
22 changes: 5 additions & 17 deletions test/import-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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;
});
});
Expand Down

0 comments on commit 69c2815

Please sign in to comment.