@@ -13,7 +13,7 @@ import { getLogger } from '../../shared/logger/logger'
1313import { maxFileSizeBytes } from '../limits'
1414import { createHash } from 'crypto'
1515import { CurrentWsFolders } from '../types'
16- import { ToolkitError } from '../../shared/errors'
16+ import { hasCode , ToolkitError } from '../../shared/errors'
1717import { AmazonqCreateUpload , Span , telemetry as amznTelemetry } from '../../shared/telemetry/telemetry'
1818import { TelemetryHelper } from './telemetryHelper'
1919import { 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 ( )
0 commit comments