-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: guard against undefined slice/map crashes in search actions #1091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,7 +27,7 @@ const uploadsSearchAction: ResearchAction<typeof schema> = { | |||||||||
| Never use this tool to search the web or for information that is not contained within the user's uploaded files. | ||||||||||
| `, | ||||||||||
| execute: async (input, additionalConfig) => { | ||||||||||
| input.queries = input.queries.slice(0, 3); | ||||||||||
| input.queries = (input.queries ?? []).slice(0, 3); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The nullish fallback is incomplete: Prompt for AI agents
Suggested change
|
||||||||||
|
|
||||||||||
| const researchBlock = additionalConfig.session.getBlock( | ||||||||||
| additionalConfig.researchBlockId, | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,8 @@ export const searchSearxng = async ( | |
|
|
||
| const data = await res.json(); | ||
|
|
||
| const results: SearxngSearchResult[] = data.results; | ||
| const suggestions: string[] = data.suggestions; | ||
| const results: SearxngSearchResult[] = data.results ?? []; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| const suggestions: string[] = data.suggestions ?? []; | ||
|
|
||
| return { results, suggestions }; | ||
| } catch (err: any) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
?? []avoids only null/undefined, but non-arrayurlsvalues can still crash.slice()/.map()at runtime.Prompt for AI agents