|
| 1 | +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package software.aws.toolkits.jetbrains.services.codewhisperer.codetest |
| 5 | + |
| 6 | +import software.aws.toolkits.resources.message |
| 7 | + |
| 8 | +open class CodeTestException( |
| 9 | + override val message: String?, |
| 10 | + val statusCode: String? = "400", |
| 11 | + val code: String? = "DefaultError", |
| 12 | + val uiMessage: String? = message( |
| 13 | + "testgen.error.generic_error_message" |
| 14 | + ), |
| 15 | +) : RuntimeException() |
| 16 | + |
| 17 | +open class CodeTestServerException( |
| 18 | + override val message: String?, |
| 19 | + val statusCode: String? = "400", |
| 20 | + val code: String? = "DefaultError", |
| 21 | + val uiMessage: String? = message( |
| 22 | + "testgen.error.generic_technical_error_message" |
| 23 | + ), |
| 24 | +) : RuntimeException() |
| 25 | + |
| 26 | +internal fun noFileOpenError(): Nothing = |
| 27 | + throw CodeTestException(message("codewhisperer.codescan.no_file_open"), "400", "ProjectZipError") |
| 28 | + |
| 29 | +internal fun fileTooLarge(): Nothing = |
| 30 | + throw CodeTestException(message("codewhisperer.codescan.file_too_large_telemetry"), "400", "ProjectZipError") |
| 31 | + |
| 32 | +internal fun cannotFindFile(errorMessage: String, filepath: String): Nothing = |
| 33 | + error(message("codewhisperer.codescan.file_not_found", filepath, errorMessage)) |
| 34 | + |
| 35 | +internal fun cannotFindValidFile(errorMessage: String): Nothing = |
| 36 | + throw CodeTestException(errorMessage, "400", "ProjectZipError") |
| 37 | + |
| 38 | +internal fun cannotFindBuildArtifacts(errorMessage: String): Nothing = |
| 39 | + throw CodeTestException(errorMessage, "400", "ProjectZipError") |
| 40 | + |
| 41 | +internal fun invalidSourceZipError(): Nothing = |
| 42 | + throw CodeTestException(message("codewhisperer.codescan.invalid_source_zip_telemetry"), "400", "InvalidSourceZipError") |
| 43 | + |
| 44 | +fun codeTestServerException(errorMessage: String, statusCode: String?, code: String?, uiMessage: String?): Nothing = |
| 45 | + throw CodeTestServerException(errorMessage, statusCode, code, uiMessage) |
| 46 | + |
| 47 | +fun testGenStoppedError(): Nothing = |
| 48 | + throw CodeTestException(message("testgen.message.cancelled"), "400", "TestGenCancelled", message("testgen.message.cancelled")) |
0 commit comments