Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove extra warning on code snippet extend error #1031

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/error-snippets/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { findRelevantStackFrame, resolveLocationWithStackFrame } from "./frames";
import { extractSourceMaps, resolveLocationWithSourceMap } from "./source-maps";
import { getSourceCodeFile, formatErrorSnippet, shouldNotAddCodeSnippet } from "./utils";
import logger from "../utils/logger";
import type { ResolvedFrame, SufficientStackFrame, WithSnippetError } from "./types";

const stackFrameLocationResolver = async (stackFrame: SufficientStackFrame): Promise<ResolvedFrame> => {
Expand Down Expand Up @@ -31,8 +30,6 @@ export const extendWithCodeSnippet = async (err: WithSnippetError): Promise<With

return err;
} catch (snippetError) {
logger.warn("Unable to apply code snippet:", snippetError);

return err;
}
};
14 changes: 2 additions & 12 deletions test/src/error-snippets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ describe("error-snippets", () => {
let fetchStub: SinonStub;
let formatErrorSnippetStub: SinonStub;
let findRelevantStackFrameStub: SinonStub;
let loggerStub: { warn: SinonStub };

beforeEach(() => {
fsReadFileStub = sandbox.stub(fs, "readFile");
fetchStub = sandbox.stub(globalThis, "fetch");

formatErrorSnippetStub = sandbox.stub();
findRelevantStackFrameStub = sandbox.stub();
loggerStub = { warn: sandbox.stub() };

extendWithCodeSnippet = proxyquire("../../../src/error-snippets", {
"./utils": { formatErrorSnippet: formatErrorSnippetStub },
"./frames": { findRelevantStackFrame: findRelevantStackFrameStub },
"../utils/logger": loggerStub,
}).extendWithCodeSnippet;
});

Expand All @@ -63,8 +60,6 @@ describe("error-snippets", () => {
await assert.eventually.isUndefined(extendWithCodeSnippet());
await assert.eventually.isNull(extendWithCodeSnippet(null));
await assert.eventually.equal(extendWithCodeSnippet(""), "");

assert.notCalled(loggerStub.warn);
});

it("should not modify error, if could not find relevant stack frame", async () => {
Expand All @@ -74,7 +69,6 @@ describe("error-snippets", () => {

await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.strictEqual(error, savedError);
});

Expand All @@ -89,7 +83,6 @@ describe("error-snippets", () => {

assert.strictEqual(error, savedError);
assert.strictEqual(error, result);
assert.calledOnceWith(loggerStub.warn, "Unable to apply code snippet:");
});

it("should return the same Object.is object", async () => {
Expand All @@ -101,7 +94,6 @@ describe("error-snippets", () => {

const result = await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.equal(error, result);
});

Expand All @@ -114,7 +106,6 @@ describe("error-snippets", () => {

const result = await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.equal(result.snippet, "code snippet");
});

Expand All @@ -130,7 +121,6 @@ describe("error-snippets", () => {

const result = await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.equal(result.snippet, "code snippet");
});

Expand All @@ -141,9 +131,9 @@ describe("error-snippets", () => {
fsReadFileStub.returns("source code");
formatErrorSnippetStub.throws(new Error());

await extendWithCodeSnippet(error);
const returnedError = await extendWithCodeSnippet(error);

assert.calledOnceWith(loggerStub.warn, "Unable to apply code snippet:");
assert.strictEqual(error, returnedError);
});
});
});
Loading