Skip to content

Commit e0f9029

Browse files
neilk-awskaranA-aws
authored andcommitted
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 be3b946 commit e0f9029

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'
@@ -48,7 +48,16 @@ export async function prepareRepoData(
4848
const ignoredExtensionMap = new Map<string, number>()
4949

5050
for (const file of files) {
51-
const fileSize = (await fs.stat(file.fileUri)).size
51+
let fileSize
52+
try {
53+
fileSize = (await fs.stat(file.fileUri)).size
54+
} catch (error) {
55+
if (hasCode(error) && error.code === 'ENOENT') {
56+
// No-op: Skip if file does not exist
57+
continue
58+
}
59+
throw error
60+
}
5261
const isCodeFile_ = isCodeFile(file.relativeFilePath)
5362
// exclude user's devfile if `useAutoBuildFeature` is set to false
5463
const excludeDevFile = useAutoBuildFeature ? false : file.relativeFilePath === 'devfile.yaml'
@@ -69,7 +78,17 @@ export async function prepareRepoData(
6978
totalBytes += fileSize
7079

7180
const zipFolderPath = path.dirname(file.zipFilePath)
72-
zip.addLocalFile(file.fileUri.fsPath, zipFolderPath)
81+
82+
try {
83+
zip.addLocalFile(file.fileUri.fsPath, zipFolderPath)
84+
} catch (error) {
85+
if (error instanceof Error && error.message.includes('File not found')) {
86+
// No-op: Skip if file was deleted or does not exist
87+
// Reference: https://github.com/cthackers/adm-zip/blob/1cd32f7e0ad3c540142a76609bb538a5cda2292f/adm-zip.js#L296-L321
88+
continue
89+
}
90+
throw error
91+
}
7392
}
7493

7594
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)