@@ -14,7 +14,8 @@ import { AWSError } from 'aws-sdk'
14
14
import { isAwsError } from '../../shared/errors'
15
15
import { TelemetryHelper } from '../util/telemetryHelper'
16
16
import { getLogger } from '../../shared/logger'
17
- import { isCloud9 } from '../../shared/extensionUtilities'
17
+ import { isCloud9 , isSageMaker } from '../../shared/extensionUtilities'
18
+ import { hasVendedIamCredentials } from '../../auth/auth'
18
19
import {
19
20
asyncCallWithTimeout ,
20
21
isInlineCompletionEnabled ,
@@ -40,6 +41,7 @@ import { AuthUtil } from '../util/authUtil'
40
41
import { CodeWhispererUserGroupSettings } from '../util/userGroupUtil'
41
42
import { CWInlineCompletionItemProvider } from './inlineCompletionItemProvider'
42
43
import { application } from '../util/codeWhispererApplication'
44
+ import { openUrl } from '../../shared/utilities/vsCodeUtils'
43
45
import { indent } from '../../shared/utilities/textUtilities'
44
46
45
47
/**
@@ -110,8 +112,10 @@ export class RecommendationHandler {
110
112
isFirstPaginationCall : boolean ,
111
113
promise : Promise < any >
112
114
) : Promise < any > {
113
- const timeoutMessage = isCloud9 ( ) ? `Generate recommendation timeout.` : `List recommendation timeout`
114
- if ( isManualTriggerOn && triggerType === 'OnDemand' && ( isCloud9 ( ) || isFirstPaginationCall ) ) {
115
+ const timeoutMessage = hasVendedIamCredentials ( )
116
+ ? 'Generate recommendation timeout.'
117
+ : 'List recommendation timeout'
118
+ if ( isManualTriggerOn && triggerType === 'OnDemand' && ( hasVendedIamCredentials ( ) || isFirstPaginationCall ) ) {
115
119
return vscode . window . withProgress (
116
120
{
117
121
location : vscode . ProgressLocation . Notification ,
@@ -154,6 +158,7 @@ export class RecommendationHandler {
154
158
autoTriggerType ?: CodewhispererAutomatedTriggerType ,
155
159
pagination : boolean = true ,
156
160
page : number = 0 ,
161
+ isSM : boolean = isSageMaker ( ) ,
157
162
retry : boolean = false
158
163
) : Promise < GetRecommendationsResponse > {
159
164
let invocationResult : 'Succeeded' | 'Failed' = 'Failed'
@@ -227,9 +232,8 @@ export class RecommendationHandler {
227
232
startTime = performance . now ( )
228
233
this . lastInvocationTime = startTime
229
234
const mappedReq = runtimeLanguageContext . mapToRuntimeLanguage ( request )
230
- const codewhispererPromise = pagination
231
- ? client . listRecommendations ( mappedReq )
232
- : client . generateRecommendations ( mappedReq )
235
+ const codewhispererPromise =
236
+ pagination && ! isSM ? client . listRecommendations ( mappedReq ) : client . generateRecommendations ( mappedReq )
233
237
const resp = await this . getServerResponse (
234
238
triggerType ,
235
239
config . isManualTriggerEnabled ,
@@ -270,6 +274,18 @@ export class RecommendationHandler {
270
274
errorCode = error . code
271
275
reason = `CodeWhisperer Invocation Exception: ${ error ?. code ?? error ?. name ?? 'unknown' } `
272
276
await this . onThrottlingException ( error , triggerType )
277
+
278
+ if ( error ?. code === 'AccessDeniedException' && errorMessage ?. includes ( 'no identity-based policy' ) ) {
279
+ getLogger ( ) . error ( 'CodeWhisperer AccessDeniedException : %s' , ( error as Error ) . message )
280
+ vscode . window
281
+ . showErrorMessage ( `CodeWhisperer: ${ error ?. message } ` , CodeWhispererConstants . settingsLearnMore )
282
+ . then ( async resp => {
283
+ if ( resp === CodeWhispererConstants . settingsLearnMore ) {
284
+ openUrl ( vscode . Uri . parse ( CodeWhispererConstants . learnMoreUri ) )
285
+ }
286
+ } )
287
+ await vscode . commands . executeCommand ( 'aws.codeWhisperer.enableCodeSuggestions' , false )
288
+ }
273
289
} else {
274
290
errorMessage = error as string
275
291
reason = error ? String ( error ) : 'unknown'
0 commit comments