Skip to content

Commit 6aee519

Browse files
committed
fix: use QueryModeError in local-executor + void fire-and-forget promises
local-executor.ts: 6 throw sites used plain Error instead of QueryModeError — callers couldn't match on error codes (TABLE_NOT_FOUND, INVALID_FORMAT). Converted all to structured errors with appropriate codes. query-do.ts: 3 edgeCachePut wrappers discarded promises without void operator — added explicit void to mark fire-and-forget intent.
1 parent 22618ec commit 6aee519

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/local-executor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ export class LocalExecutor implements QueryExecutor {
677677
const manifestBuf = await fs.readFile(pathMod.join(versionsDir, manifestFile));
678678
const ab = manifestBuf.buffer.slice(manifestBuf.byteOffset, manifestBuf.byteOffset + manifestBuf.byteLength);
679679
const manifest = parseManifest(ab);
680-
if (!manifest) throw new Error(`Failed to parse manifest for version ${version}`);
680+
if (!manifest) throw new QueryModeError("INVALID_FORMAT", `Failed to parse manifest for version ${version}`);
681681
return { paths: new Set(manifest.fragments.map(f => f.filePath)), manifest };
682682
};
683683

@@ -720,22 +720,22 @@ export class LocalExecutor implements QueryExecutor {
720720
const manifests = entries.filter(e => e.endsWith(".manifest"))
721721
.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
722722
if (manifests.length === 0) {
723-
throw new Error(`No manifests found in ${versionsDir}`);
723+
throw new QueryModeError("TABLE_NOT_FOUND", `No manifests found in ${versionsDir}`);
724724
}
725725

726726
let targetManifest: string;
727727
if (version != null) {
728728
targetManifest = `${version}.manifest`;
729729
if (!manifests.includes(targetManifest)) {
730-
throw new Error(`Version ${version} not found in ${versionsDir}. Available: ${manifests.join(", ")}`);
730+
throw new QueryModeError("TABLE_NOT_FOUND", `Version ${version} not found in ${versionsDir}. Available: ${manifests.join(", ")}`);
731731
}
732732
} else {
733733
targetManifest = manifests[manifests.length - 1];
734734
}
735735
const manifestBuf = await fs.readFile(pathMod.join(versionsDir, targetManifest));
736736
const ab = manifestBuf.buffer.slice(manifestBuf.byteOffset, manifestBuf.byteOffset + manifestBuf.byteLength);
737737
const manifest = parseManifest(ab);
738-
if (!manifest) throw new Error(`Failed to parse manifest ${targetManifest}`);
738+
if (!manifest) throw new QueryModeError("INVALID_FORMAT", `Failed to parse manifest ${targetManifest}`);
739739

740740
const fragmentMetas = new Map<number, TableMeta>();
741741
for (const frag of manifest.fragments) {
@@ -792,7 +792,7 @@ export class LocalExecutor implements QueryExecutor {
792792
updatedAt: Date.now(),
793793
});
794794
} catch (err) {
795-
throw new Error(`Failed to load fragment ${frag.filePath}: ${err instanceof Error ? err.message : String(err)}`);
795+
throw QueryModeError.from(err, { table: frag.filePath, operation: "load fragment" });
796796
}
797797
}
798798

@@ -1000,7 +1000,7 @@ export class LocalExecutor implements QueryExecutor {
10001000
// Get file size
10011001
const headResp = await fetch(url, { method: "HEAD" });
10021002
const fileSize = Number(headResp.headers.get("content-length") ?? 0);
1003-
if (fileSize < 8) throw new Error(`File too small: ${url}`);
1003+
if (fileSize < 8) throw new QueryModeError("INVALID_FORMAT", `File too small: ${url}`);
10041004

10051005
// Read tail for format detection (last 40 bytes)
10061006
const tailSize = Math.min(fileSize, FOOTER_SIZE);

src/query-do.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ export class QueryDO extends DurableObject<Env> {
12141214
const scan = new EdgeScanOperator(
12151215
this.r2(meta.r2Key), this.wasmEngine, meta, query, this.footerCache,
12161216
(r2Key, offset, length) => this.edgeCacheGet(r2Key, offset, length),
1217-
(r2Key, offset, length, data) => { this.edgeCachePut(r2Key, offset, length, data); },
1217+
(r2Key, offset, length, data) => { void this.edgeCachePut(r2Key, offset, length, data); },
12181218
);
12191219

12201220
const outputColumns = query.projections.length > 0
@@ -1262,7 +1262,7 @@ export class QueryDO extends DurableObject<Env> {
12621262
{ ...query, sortColumn: undefined, limit: undefined, offset: undefined, aggregates: undefined, join: undefined },
12631263
this.footerCache,
12641264
(r2Key, offset, length) => this.edgeCacheGet(r2Key, offset, length),
1265-
(r2Key, offset, length, data) => { this.edgeCachePut(r2Key, offset, length, data); },
1265+
(r2Key, offset, length, data) => { void this.edgeCachePut(r2Key, offset, length, data); },
12661266
);
12671267
let leftPipeline: Operator = leftScan;
12681268
if (query.filters.length > 0 || (query.filterGroups && query.filterGroups.length > 0)) {
@@ -1281,7 +1281,7 @@ export class QueryDO extends DurableObject<Env> {
12811281
this.r2(rightMeta.r2Key), this.wasmEngine, rightMeta, join.right,
12821282
this.footerCache,
12831283
(r2Key, offset, length) => this.edgeCacheGet(r2Key, offset, length),
1284-
(r2Key, offset, length, data) => { this.edgeCachePut(r2Key, offset, length, data); },
1284+
(r2Key, offset, length, data) => { void this.edgeCachePut(r2Key, offset, length, data); },
12851285
);
12861286
let rightPipeline: Operator = rightScan;
12871287
if (join.right.filters.length > 0 || (join.right.filterGroups && join.right.filterGroups.length > 0)) {

0 commit comments

Comments
 (0)