Skip to content

Commit 5e1a94b

Browse files
authored
fix(amazonq): skip including deleted files for FeatureDev context aws#6312
## Problem When zipping context for /dev, customer build processes (file watchers, etc.) may delete build artifacts we’ve already enumerated but have not added to the archive. As a best practice, customers should `.gitignore` these types of files, but in the event they don't, this has the potential to block /dev from running. ## Solution Skip affected files, which are not found when adding to zip context for Feature Dev.
1 parent d939f2b commit 5e1a94b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q /dev: Fix issue when files are deleted while preparing context"
4+
}

packages/core/src/amazonqFeatureDev/util/files.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getLogger } from '../../shared/logger/logger'
1313
import { maxFileSizeBytes } from '../limits'
1414
import { createHash } from 'crypto'
1515
import { CurrentWsFolders } from '../types'
16-
import { ToolkitError } from '../../shared/errors'
16+
import { hasCode, ToolkitError } from '../../shared/errors'
1717
import { AmazonqCreateUpload, Span, telemetry as amznTelemetry } from '../../shared/telemetry/telemetry'
1818
import { TelemetryHelper } from './telemetryHelper'
1919
import { maxRepoSizeBytes } from '../constants'
@@ -39,7 +39,16 @@ export async function prepareRepoData(
3939
const ignoredExtensionMap = new Map<string, number>()
4040

4141
for (const file of files) {
42-
const fileSize = (await fs.stat(file.fileUri)).size
42+
let fileSize
43+
try {
44+
fileSize = (await fs.stat(file.fileUri)).size
45+
} catch (error) {
46+
if (hasCode(error) && error.code === 'ENOENT') {
47+
// No-op: Skip if file does not exist
48+
continue
49+
}
50+
throw error
51+
}
4352
const isCodeFile_ = isCodeFile(file.relativeFilePath)
4453

4554
if (fileSize >= maxFileSizeBytes || !isCodeFile_) {
@@ -58,7 +67,17 @@ export async function prepareRepoData(
5867
totalBytes += fileSize
5968

6069
const zipFolderPath = path.dirname(file.zipFilePath)
61-
zip.addLocalFile(file.fileUri.fsPath, zipFolderPath)
70+
71+
try {
72+
zip.addLocalFile(file.fileUri.fsPath, zipFolderPath)
73+
} catch (error) {
74+
if (error instanceof Error && error.message.includes('File not found')) {
75+
// No-op: Skip if file was deleted or does not exist
76+
// Reference: https://github.com/cthackers/adm-zip/blob/1cd32f7e0ad3c540142a76609bb538a5cda2292f/adm-zip.js#L296-L321
77+
continue
78+
}
79+
throw error
80+
}
6281
}
6382

6483
const iterator = ignoredExtensionMap.entries()

packages/core/src/shared/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ export function isAwsError(error: unknown): error is AWSError & { error_descript
599599
return error instanceof Error && hasCode(error) && hasTime(error)
600600
}
601601

602-
function hasCode<T>(error: T): error is T & { code: string } {
602+
export function hasCode<T>(error: T): error is T & { code: string } {
603603
return typeof (error as { code?: unknown }).code === 'string'
604604
}
605605

0 commit comments

Comments
 (0)