Skip to content

Commit e3d1d5b

Browse files
fix: (cy.prompt) add more context to the error message shown when cy.prompt() fails to download (#32822)
1 parent 7b6ad1d commit e3d1d5b

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ _Released 10/20/2025 (PENDING)_
1212
- Fixed an issue where grouped command text jumps up and down when expanding and collapsing in the command log. Addressed in [#32757](https://github.com/cypress-io/cypress/pull/32757).
1313
- Fixed an issue where command snapshots were not correctly displayed in Studio. Addressed in [#32808](https://github.com/cypress-io/cypress/pull/32808).
1414
- Fixed an issue with grouped console prop items having a hard to read blue color in the console log and duplicate `:` characters being displayed. Addressed in [#32776](https://github.com/cypress-io/cypress/pull/32776).
15+
- Added more context to the error message shown when `cy.prompt()` fails to download. Addressed in [#32822](https://github.com/cypress-io/cypress/pull/32822).
1516

1617
**Misc:**
1718

packages/server/lib/cloud/cy-prompt/CyPromptLifecycleManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class CyPromptLifecycleManager {
8888
const cloudUrl = ctx.cloud.getCloudUrl(cloudEnv)
8989
const cloudHeaders = await ctx.cloud.additionalHeaders()
9090

91+
const lastError = error instanceof AggregateError ? error.errors[error.errors.length - 1] : error
92+
9193
reportCyPromptError({
9294
cloudApi: {
9395
cloudUrl,
@@ -99,15 +101,15 @@ export class CyPromptLifecycleManager {
99101
additionalHeaders: cloudHeaders,
100102
cyPromptHash: this.cyPromptHash,
101103
projectSlug: (await ctx.project.getConfig()).projectId || undefined,
102-
error,
104+
error: lastError,
103105
cyPromptMethod: 'initializeCyPromptManager',
104106
cyPromptMethodArgs: [],
105107
})
106108

107109
// Clean up any registered listeners
108110
this.listeners = []
109111

110-
return { error }
112+
return { error: lastError }
111113
})
112114

113115
this.cyPromptManagerPromise = cyPromptManagerPromise

packages/server/test/unit/cloud/cy-prompt/CyPromptLifecycleManager_spec.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,85 @@ describe('CyPromptLifecycleManager', () => {
566566
},
567567
})
568568
})
569+
570+
it('handles errors from ensureCyPromptBundle', async () => {
571+
const actualError = new Error('Test error')
572+
573+
ensureCyPromptBundleStub.rejects(actualError)
574+
cyPromptLifecycleManager.initializeCyPromptManager({
575+
cloudDataSource: mockCloudDataSource,
576+
ctx: mockCtx,
577+
record: false,
578+
key: '123e4567-e89b-12d3-a456-426614174000',
579+
})
580+
581+
// @ts-expect-error - accessing private property
582+
const cyPromptPromise = cyPromptLifecycleManager.cyPromptManagerPromise
583+
584+
expect(cyPromptPromise).to.not.be.null
585+
586+
const { error } = (await cyPromptPromise) as { error: Error }
587+
588+
expect(error.message).to.equal('Test error')
589+
590+
expect(reportCyPromptErrorStub).to.be.calledWith({
591+
cloudApi: {
592+
cloudUrl: 'https://cloud.cypress.io',
593+
CloudRequest,
594+
createCloudRequest,
595+
isRetryableError,
596+
asyncRetry,
597+
},
598+
cyPromptHash: 'abc',
599+
projectSlug: 'test-project-id',
600+
error: actualError,
601+
cyPromptMethod: 'initializeCyPromptManager',
602+
cyPromptMethodArgs: [],
603+
additionalHeaders: {
604+
'Authorization': 'Bearer test-token',
605+
},
606+
})
607+
})
608+
609+
it('handles AggregateErrors from ensureCyPromptBundle', async () => {
610+
const aggregateError = new AggregateError([new Error('Test error'), new Error('Second error')], 'Multiple errors')
611+
612+
ensureCyPromptBundleStub.rejects(aggregateError)
613+
614+
cyPromptLifecycleManager.initializeCyPromptManager({
615+
cloudDataSource: mockCloudDataSource,
616+
ctx: mockCtx,
617+
record: false,
618+
key: '123e4567-e89b-12d3-a456-426614174000',
619+
})
620+
621+
// @ts-expect-error - accessing private property
622+
const cyPromptPromise = cyPromptLifecycleManager.cyPromptManagerPromise
623+
624+
expect(cyPromptPromise).to.not.be.null
625+
626+
const { error } = (await cyPromptPromise) as { error: Error }
627+
628+
expect(error.message).to.equal('Second error')
629+
630+
expect(reportCyPromptErrorStub).to.be.calledWith({
631+
cloudApi: {
632+
cloudUrl: 'https://cloud.cypress.io',
633+
CloudRequest,
634+
createCloudRequest,
635+
isRetryableError,
636+
asyncRetry,
637+
},
638+
cyPromptHash: 'abc',
639+
projectSlug: 'test-project-id',
640+
error: aggregateError.errors[aggregateError.errors.length - 1],
641+
cyPromptMethod: 'initializeCyPromptManager',
642+
cyPromptMethodArgs: [],
643+
additionalHeaders: {
644+
'Authorization': 'Bearer test-token',
645+
},
646+
})
647+
})
569648
})
570649

571650
describe('getCyPrompt', () => {

0 commit comments

Comments
 (0)