Skip to content

Commit 454890d

Browse files
authored
Improving telemetry error messages (#4565)
* Improving error messages
1 parent b44c952 commit 454890d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,7 @@ class CodeWhispererCodeScanManager(val project: Project) {
399399
is CodeWhispererCodeScanServerException -> e.message
400400
is WaiterTimeoutException, is TimeoutCancellationException -> message("codewhisperer.codescan.scan_timed_out")
401401
is CancellationException -> message("codewhisperer.codescan.cancelled_by_user_exception")
402-
else -> when {
403-
/**
404-
* Error message has text with user details(like requestId) which is specific so sending a custom error message to calculate the occurence of this event.
405-
*/
406-
e.message?.startsWith("Too many requests, please wait before trying again.") == true ->
407-
"Too many requests, please wait before trying again."
408-
else -> e.message
409-
}
402+
else -> e.message
410403
} ?: message("codewhisperer.codescan.run_scan_error_telemetry")
411404

412405
return telemetryErrorMessage

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanSession.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
286286
)
287287
} catch (e: Exception) {
288288
LOG.debug { "Create Upload URL failed: ${e.message}" }
289-
throw codeScanServerException("CreateUploadUrlException: " + e.message?.let { it } ?: message("codewhisperer.codescan.run_scan_error_telemetry"))
289+
290+
val errorMessage = when {
291+
e.message?.contains("Your account is not authorized to make this call.") == true -> "Your account is not authorized to make this call."
292+
e.message?.contains("Service returned HTTP status code 407") == true -> "Service returned HTTP status code 407"
293+
else -> e.message ?: message("codewhisperer.codescan.run_scan_error_telemetry")
294+
}
295+
throw codeScanServerException("CreateUploadUrlException: $errorMessage")
290296
}
291297

292298
private fun getUploadIntent(scope: CodeWhispererConstants.CodeAnalysisScope): UploadIntent = when (scope) {
@@ -341,7 +347,15 @@ class CodeWhispererCodeScanSession(val sessionContext: CodeScanSessionContext) {
341347
)
342348
} catch (e: Exception) {
343349
LOG.debug { "Creating security scan failed: ${e.message}" }
344-
throw codeScanServerException("CreateCodeScanException: " + e.message?.let { it } ?: message("codewhisperer.codescan.run_scan_error_telemetry"))
350+
val errorMessage = when {
351+
e.message?.contains("Too many requests, please wait before trying again.") == true -> "Too many requests, please wait before trying again."
352+
e.message?.contains("Improperly formed request.") == true -> "Improperly formed request."
353+
e.message?.contains("Service returned HTTP status code 407") == true -> "Service returned HTTP status code 407"
354+
e.message?.contains("Encountered an unexpected error when processing the request, please try again.") == true ->
355+
"Encountered an unexpected error when processing the request, please try again."
356+
else -> e.message ?: message("codewhisperer.codescan.run_scan_error_telemetry")
357+
}
358+
throw codeScanServerException("CreateCodeScanException: $errorMessage")
345359
}
346360
}
347361

0 commit comments

Comments
 (0)