Skip to content

Commit 825288a

Browse files
committed
Add error handling for fetching related objects in context gathering
1 parent 8a5bc07 commit 825288a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/aiProviders/prompt.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,23 @@ export async function getContextItems(input: string, options: PromptOptions = {}
7777
// If the user referenced a table, view, or other object, let's fetch related objects
7878
progress(`Finding objects related to ${prettyNameRef}...`);
7979

80-
const relatedObjects = await Schemas.getRelatedObjects(ref);
81-
const contentItems = await getContentItemsForRefs(relatedObjects);
82-
83-
contextItems.push(...contentItems);
84-
85-
// Then also add some follow ups
86-
if (relatedObjects.length === 1) {
87-
followUps.push(`How is ${prettyNameRef} related to ${Statement.prettyName(relatedObjects[0].name)}?`);
88-
} else if (ref.sqlType === `TABLE`) {
89-
followUps.push(`What are some objects related to that table?`);
80+
try {
81+
const relatedObjects = await Schemas.getRelatedObjects(ref);
82+
const contentItems = await getContentItemsForRefs(relatedObjects);
83+
84+
contextItems.push(...contentItems);
85+
86+
// Then also add some follow ups
87+
if (relatedObjects.length === 1) {
88+
followUps.push(`How is ${prettyNameRef} related to ${Statement.prettyName(relatedObjects[0].name)}?`);
89+
} else if (ref.sqlType === `TABLE`) {
90+
followUps.push(`What are some objects related to that table?`);
91+
}
92+
} catch (e) {
93+
followUps.push(`What objects are in ${Statement.prettyName(ref.schema)}?`);
94+
console.log(e);
9095
}
96+
9197
}
9298

9399
} else if (userInput.refs.length > 1) {

0 commit comments

Comments
 (0)