Skip to content

Commit 7bf9a06

Browse files
committed
fix: QueryModeError.from() case-insensitive timeout detection
withTimeout throws "Timeout after Nms" (capital T) but from() checked lowercase "timeout" — case-sensitive mismatch meant timeouts were classified as QUERY_FAILED instead of QUERY_TIMEOUT/NETWORK_TIMEOUT. Now uses toLowerCase() for timeout and R2/network keyword matching. Added tests for both capital-T timeout and R2 network timeout paths.
1 parent 038c110 commit 7bf9a06

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/convenience.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ describe("error messages", () => {
154154
expect(err.message).toContain(".csv");
155155
expect(err.message).toContain(".json");
156156
});
157+
158+
it("QUERY_TIMEOUT from withTimeout-style capital-T message", () => {
159+
const err = QueryModeError.from(new Error("Timeout after 10000ms"), { table: "events" });
160+
expect(err.code).toBe("QUERY_TIMEOUT");
161+
expect(err.message).toContain("events");
162+
});
163+
164+
it("NETWORK_TIMEOUT when message mentions R2", () => {
165+
const err = QueryModeError.from(new Error("R2 read timeout"), { table: "events" });
166+
expect(err.code).toBe("NETWORK_TIMEOUT");
167+
});
157168
});
158169

159170
describe("DataFrame Pandas-like methods", () => {

src/errors.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ export class QueryModeError extends Error {
7070
);
7171
}
7272

73-
// Timeouts
74-
if (msg.includes("timeout") || msg.includes("timed out") || msg.includes("TIMEOUT")) {
75-
const code = msg.includes("network") || msg.includes("R2") ? "NETWORK_TIMEOUT" : "QUERY_TIMEOUT";
73+
// Timeouts — case-insensitive (withTimeout throws "Timeout after ...")
74+
const msgLower = msg.toLowerCase();
75+
if (msgLower.includes("timeout") || msgLower.includes("timed out")) {
76+
const code = msgLower.includes("network") || msgLower.includes("r2") ? "NETWORK_TIMEOUT" : "QUERY_TIMEOUT";
7677
return new QueryModeError(
7778
code,
7879
`${code === "NETWORK_TIMEOUT" ? "Network" : "Query"} timeout${table ? ` on ${table}` : ""}: ${msg}`,

0 commit comments

Comments
 (0)