Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/major-coats-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"slonik": minor
---

perf: use Error.prepareStackTrace
1 change: 1 addition & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ version: "0.2"
words:
- gajus
- kuizinas
- oxlint
- plpgsql
- roarr
- slonik
Expand Down
7 changes: 7 additions & 0 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { config } from "oxlint-config-canonical";
import { defineConfig } from "oxlint";

// Remove rule not yet supported by oxlint
for (const override of config.overrides ?? []) {
if (override.rules) {
delete override.rules["unicorn/no-abusive-oxlint-disable"];
}
}

export default defineConfig({
extends: [config],
ignorePatterns: ["**/dist/", "**/.*/", "**/CHANGELOG.md"],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@changesets/changelog-github": "^0.5.2",
"husky": "^9.1.7",
"knip": "^5.83.1",
"oxfmt": "^0.40.0",
"oxlint": "^1",
"oxfmt": "^0.43.0",
"oxlint": "^1.58.0",
"oxlint-config-canonical": "^1"
}
}
1 change: 1 addition & 0 deletions packages/slonik/src/routines/executeQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type StackCrumb = {
lineNumber: null | number;
};

// oxlint-disable-next-line complexity
const executeQueryInternal = async (
connectionLogger: Logger,
connection: ConnectionPoolClient,
Expand Down
43 changes: 19 additions & 24 deletions packages/slonik/src/routines/getStackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,30 @@ type StackFrame = {
lineNumber: null | number;
};

// Matches V8 stack trace lines:
// at functionName (file:line:col)
// at functionName (file:line)
// at file:line:col
const v8Re = /^\s*at (?:(.*?) ?\()?((?:\/|[a-z]:\\|\\\\|file:|node:).*?):(\d+)(?::(\d+))?\)?\s*$/iu;

export const getStackTrace = (): StackFrame[] => {
// eslint-disable-next-line unicorn/error-message
const stack = new Error().stack;
const originalPrepare = Error.prepareStackTrace;

if (!stack) {
return [];
}
Error.prepareStackTrace = (_error, callSites) => callSites;

const error = {} as { stack: NodeJS.CallSite[] };
Error.captureStackTrace(error);
const callSites = error.stack;

Error.prepareStackTrace = originalPrepare;

// Skip frame 0 (this function itself)
const frames: StackFrame[] = [];

for (const line of stack.split("\n")) {
const match = v8Re.exec(line);

if (match) {
frames.push({
columnNumber: match[4] ? Number(match[4]) : null,
fileName: match[2] ?? null,
functionName: match[1] || null,
lineNumber: match[3] ? Number(match[3]) : null,
});
}
for (let i = 1; i < callSites.length; i++) {
const site = callSites[i];

frames.push({
columnNumber: site.getColumnNumber(),
fileName: site.getFileName() ?? null,
functionName: site.getFunctionName() ?? null,
lineNumber: site.getLineNumber(),
});
}

// Remove the first frame (this function itself)
return frames.slice(1);
return frames;
};
Loading
Loading