{"record":{"id":"f929973268589dd4","repo":"OrchardCMS/OrchardCore","slug":"cannot-copy-file-srcpath-because-it-does-not-exist","errorCode":null,"errorMessage":"Cannot copy file '${srcPath}' because it does not exist.","messagePattern":"Cannot copy file '(.+?)' because it does not exist\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs","lineNumber":211,"sourceCode":"\n    public async Task CopyFileAsync(string srcPath, string dstPath)\n    {\n        if (srcPath == dstPath)\n        {\n            throw new ArgumentException($\"The values for {nameof(srcPath)} and {nameof(dstPath)} must not be the same.\");\n        }\n\n        try\n        {\n            await _amazonS3Client.GetObjectMetadataAsync(new GetObjectMetadataRequest\n            {\n                BucketName = _options.BucketName,\n                Key = this.Combine(_basePrefix, srcPath),\n            });\n        }\n        catch (AmazonS3Exception ex) when (ex.StatusCode == HttpStatusCode.NotFound)\n        {\n            throw new FileStoreException($\"Cannot copy file '{srcPath}' because it does not exist.\");\n        }\n        catch (AmazonS3Exception ex)\n        {\n            throw new FileStoreException($\"Error accessing file '{srcPath}': {ex.Message}\", ex);\n        }\n\n        try\n        {\n            var listObjects = await _amazonS3Client.ListObjectsV2Async(new ListObjectsV2Request\n            {\n                BucketName = _options.BucketName,\n                Prefix = this.Combine(_basePrefix, dstPath),\n            });\n\n            if (listObjects.S3Objects?.Count > 0)\n            {\n                throw new ExistsFileStoreException($\"Cannot copy file '{srcPath}' because a file already exists in the new path '{dstPath}'.\");\n            }","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs#L193-L229","documentation":"CopyFileAsync first calls GetObjectMetadataAsync to verify the source file exists. When S3 returns a 404 (AmazonS3Exception with HttpStatusCode.NotFound), the method wraps it in a FileStoreException stating the source file does not exist, since there is nothing to copy.","triggerScenarios":"CopyFileAsync(srcPath, dstPath) where no object exists at the combined base prefix + srcPath key in the bucket; also surfaced through MoveFileAsync.","commonSituations":"Wrong bucket or BasePath configured in the AWS S3 options, typo in the path, file was deleted by another process/tenant, case-sensitivity mismatch (S3 keys are case-sensitive), media file removed before a copy/move operation.","solutions":["Verify the file exists with fileStore.GetFileExistsAsync(srcPath) (or IFileStore.FileExists) before copying.","Check the S3 BucketName and BasePath options point to the bucket/prefix that actually holds the file.","Confirm the exact key exists in the S3 console/CLI (aws s3 ls), including case.","Handle FileStoreException in the caller and report a friendly 'file not found' message."],"exampleFix":"// before\nawait fileStore.CopyFileAsync(srcPath, dstPath);\n\n// after\nif (!await fileStore.GetFileExistsAsync(srcPath))\n{\n    throw new InvalidOperationException($\"Source '{srcPath}' does not exist.\");\n}\nawait fileStore.CopyFileAsync(srcPath, dstPath);","handlingStrategy":"try-catch","validationCode":"if (!await fileStore.GetFileExistsAsync(srcPath))\n{\n    throw new FileNotFoundException($\"Source file '{srcPath}' was not found.\", srcPath);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await fileStore.CopyFileAsync(srcPath, dstPath);\n}\ncatch (FileStoreException ex) when (ex.Message.Contains(\"does not exist\"))\n{\n    _logger.LogWarning(\"Copy skipped, missing source '{Src}'\", srcPath);\n}","preventionTips":["Check existence before copy/move operations.","Validate BucketName/BasePath configuration at startup.","Remember S3 keys are case-sensitive; store canonical paths."],"tags":["s3","file-not-found","file-storage"],"backgroundTag":"file-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}