Skip to content

Commit 1c39fb2

Browse files
committed
feat: implement comprehensive error handling and validation
- Added DSL configuration validation with clear error messages - Implemented robust error handling for model processing - Added helpful suggestions for configuration mistakes - Created logging and debugging support Completes Prompt 9 of implementation plan
1 parent 62b13c1 commit 1c39fb2

File tree

7 files changed

+1323
-49
lines changed

7 files changed

+1323
-49
lines changed

plugins/custom-sdk-build/src/main/kotlin/aws/sdk/kotlin/gradle/customsdk/CustomSdkBuildExtension.kt

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,44 @@ open class CustomSdkBuildExtension(private val project: Project) {
7272
* Throws an exception if the configuration is invalid.
7373
*/
7474
internal fun validate() {
75-
if (serviceConfigurations.isEmpty()) {
76-
throw IllegalStateException("No services configured. Please configure at least one service.")
77-
}
78-
79-
serviceConfigurations.forEach { (serviceName, config) ->
80-
if (config.selectedOperations.isEmpty()) {
81-
throw IllegalStateException("No operations selected for service '$serviceName'. Please select at least one operation.")
75+
try {
76+
if (serviceConfigurations.isEmpty()) {
77+
throw IllegalStateException(
78+
"No services configured for custom SDK generation. " +
79+
"Add at least one service configuration using the DSL:\n" +
80+
"awsCustomSdkBuild {\n" +
81+
" s3 {\n" +
82+
" operations(S3Operation.GetObject, S3Operation.PutObject)\n" +
83+
" }\n" +
84+
"}"
85+
)
86+
}
87+
88+
serviceConfigurations.forEach { (serviceName, config) ->
89+
if (config.selectedOperations.isEmpty()) {
90+
throw IllegalStateException(
91+
"No operations selected for service '$serviceName'. " +
92+
"Add operations to your service configuration:\n" +
93+
"$serviceName {\n" +
94+
" operations(/* operation constants */)\n" +
95+
"}"
96+
)
97+
}
98+
99+
// Check for duplicate operations
100+
val duplicates = config.selectedOperations.groupingBy { it.shapeId }.eachCount().filter { it.value > 1 }
101+
if (duplicates.isNotEmpty()) {
102+
project.logger.warn("Service '$serviceName' has duplicate operations: ${duplicates.keys}")
103+
}
82104
}
105+
106+
val totalOperations = serviceConfigurations.values.sumOf { it.selectedOperations.size }
107+
project.logger.info("Extension validation passed: $totalOperations operations across ${serviceConfigurations.size} services")
108+
109+
} catch (e: Exception) {
110+
project.logger.error("Extension validation failed: ${e.message}")
111+
ErrorHandling.suggestRecoveryActions(e, project.logger)
112+
throw e
83113
}
84114
}
85115

plugins/custom-sdk-build/src/main/kotlin/aws/sdk/kotlin/gradle/customsdk/CustomSdkBuildPlugin.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class CustomSdkBuildPlugin : Plugin<Project> {
6464
// Validate the extension configuration
6565
extension.validate()
6666

67+
// Perform comprehensive validation
68+
validateConfiguration(project, extension)
69+
6770
// Log the selected operations for debugging
6871
val selectedOperations = extension.getSelectedOperations()
6972
project.logger.info("Custom SDK configuration:")
@@ -153,6 +156,33 @@ class CustomSdkBuildPlugin : Plugin<Project> {
153156
project.logger.info("Build optimizations configured for custom SDK generation")
154157
}
155158

159+
/**
160+
* Validate the plugin configuration comprehensively.
161+
*/
162+
private fun validateConfiguration(project: Project, extension: CustomSdkBuildExtension) {
163+
try {
164+
val selectedOperations = extension.getSelectedOperations()
165+
val packageName = "aws.sdk.kotlin.services.custom" // Default package name
166+
val packageVersion = project.version.toString()
167+
168+
val validationResult = ValidationEngine.validateConfiguration(
169+
project, selectedOperations, packageName, packageVersion
170+
)
171+
172+
// Log validation results
173+
ValidationEngine.logValidationResults(project.logger, validationResult)
174+
175+
// Throw exception if validation failed
176+
if (!validationResult.isValid) {
177+
ValidationEngine.throwValidationException(validationResult)
178+
}
179+
180+
} catch (e: Exception) {
181+
ErrorHandling.suggestRecoveryActions(e, project.logger)
182+
throw e
183+
}
184+
}
185+
156186
/**
157187
* Create placeholder model files for demonstration.
158188
* In a real implementation, these would be the actual AWS service models.

0 commit comments

Comments
 (0)