Skip to content

Commit b7aad87

Browse files
authored
fix: add fs exists check for system prompts directory (#10)
* feat(amazonq): saved prompts * fix: remove unecessary change * feat(amazonq): saved prompts * fix: remove unecessary change * fix: add fs exists check for ~/.aws/prompts * fix: whitespace
1 parent 280f4e5 commit b7aad87

File tree

1 file changed

+13
-10
lines changed
  • packages/core/src/codewhispererChat/controllers/chat

1 file changed

+13
-10
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,19 @@ export class ChatController {
479479
// Check ~/.aws/prompts for saved prompts
480480
try {
481481
const systemPromptsDirectory = path.join(fs.getUserHomeDir(), '.aws', 'prompts')
482-
const systemPromptFiles = await fs.readdir(systemPromptsDirectory)
483-
promptsCmd.children?.[0].commands.push(
484-
...systemPromptFiles
485-
.filter(([name]) => name.endsWith('.prompt'))
486-
.map(([name]) => ({
487-
command: name.replace(/\.prompt$/, ''),
488-
icon: 'magic' as MynahIconsType,
489-
route: [systemPromptsDirectory, name],
490-
}))
491-
)
482+
const directoryExists = await fs.exists(systemPromptsDirectory)
483+
if (directoryExists) {
484+
const systemPromptFiles = await fs.readdir(systemPromptsDirectory)
485+
promptsCmd.children?.[0].commands.push(
486+
...systemPromptFiles
487+
.filter(([name]) => name.endsWith('.prompt'))
488+
.map(([name]) => ({
489+
command: name.replace(/\.prompt$/, ''),
490+
icon: 'magic' as MynahIconsType,
491+
route: [systemPromptsDirectory, name],
492+
}))
493+
)
494+
}
492495
} catch (e) {
493496
getLogger().verbose(`Could not read prompts from ~/.aws/prompts: ${e}`)
494497
}

0 commit comments

Comments
 (0)