Skip to content

Commit 9ea08da

Browse files
committed
Improve recast error handling
1 parent 9c2fdf8 commit 9ea08da

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

typescript/packages/toolshed/routes/ai/spell/behavior/effects.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ export class MemoryError extends Error {
2121
}
2222

2323
function handleErrorResponse(data: any) {
24+
if (typeof data.error === "string") {
25+
throw new MemoryError(data.error, data);
26+
}
2427
if ("cause" in data.error) {
2528
throw new MemoryError(data?.error?.cause?.message, data);
2629
} else {
27-
throw new MemoryError(data?.error?.message, data);
30+
throw new MemoryError(data?.error?.message || "Unknown error", data);
2831
}
2932
}
3033

typescript/packages/toolshed/routes/ai/spell/spell.handlers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,14 @@ async function processRecast(
446446
const argument = source.value.argument;
447447
const type = source.value.$TYPE;
448448
logger.debug({ type, argument }, "Extracted argument and type from source");
449-
450449
const spellId = "spell-" + type;
451450
logger.info({ spellId }, "Looking up spell");
452451

453452
const spell = await getBlob<Spell>(spellId);
454453
logger.info({ spellId }, "Retrieved spell");
454+
if (!spell) {
455+
throw new Error("No spell found for id: " + spellId);
456+
}
455457

456458
const schema = spell.recipe.argumentSchema;
457459
logger.debug({ schema }, "Extracted argument schema from spell");

0 commit comments

Comments
 (0)