Skip to content

Commit

Permalink
Merge pull request #92 from vlovich/throw-error-instead-of-string
Browse files Browse the repository at this point in the history
Make sure that errors throw Error instead of string
  • Loading branch information
hipstersmoothie authored May 16, 2023
2 parents 617373e + ddcafc3 commit 7ae02f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,11 @@ function gitlog<Field extends CommitField = DefaultField>(

debug("commits", commits);

cb(
stderr || err,
parseCommits(commits, options.fields, options.nameStatus)
);
if (stderr) {
err = new Error(stderr);
}

cb(err, parseCommits(commits, options.fields, options.nameStatus));
});
}

Expand Down
6 changes: 6 additions & 0 deletions test/gitlog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ describe("gitlog", () => {
);
});

it("throws an error when bad option - promise", async () => {
await expect(
gitlogPromise({ repo: testRepoLocation, branch: "not-a-branch" })
).rejects.toBeInstanceOf(Error);
});

it("returns 21 commits from specified branch", (done) => {
gitlog(
{ repo: testRepoLocation, branch: "new-branch", number: 100 },
Expand Down

0 comments on commit 7ae02f8

Please sign in to comment.