Skip to content

Commit a4c2b86

Browse files
committed
fix: update error messages for empty and blank input validation
1 parent 129ae7e commit a4c2b86

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

prompts/12-sdkman_bash_cli_download-todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Consider the following rules during execution of the tasks:
2121

2222
### Task 2: Improve Error Messages for Empty/Blank Input Validation
2323

24-
- [ ] Update error messages for empty and blank input validation to use "[empty/blank]" format
24+
- [X] Update error messages for empty and blank input validation to use "[empty/blank]" format
2525

2626
**Description**: The test cases for empty and blank input validation currently use the actual empty/blank values as error messages. The TODO comments suggest these should be changed to a more descriptive "[empty/blank]" format for better error reporting and consistency.
2727

src/main/kotlin/io/sdkman/broker/application/service/SdkmanCliDownloadServiceImpl.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ class SdkmanCliDownloadServiceImpl : SdkmanCliDownloadService {
3434
if (version.isNotBlank()) {
3535
version.right()
3636
} else {
37-
VersionError.InvalidVersion(version).left()
37+
VersionError.InvalidVersion("[empty/blank]").left()
3838
}
3939

4040
private fun validatePlatform(platformCode: String): Either<VersionError, Platform> =
41-
Platform.fromCode(platformCode)
42-
.toEither { VersionError.InvalidPlatform(platformCode) }
41+
if (platformCode.isBlank()) {
42+
VersionError.InvalidPlatform("[empty/blank]").left()
43+
} else {
44+
Platform.fromCode(platformCode)
45+
.toEither { VersionError.InvalidPlatform(platformCode) }
46+
}
4347

4448
private fun constructDownloadInfo(version: String): SdkmanCliDownloadInfo {
4549
val tag = if (version.startsWith("latest+")) "latest" else version

src/test/kotlin/io/sdkman/broker/application/service/SdkmanCliDownloadServiceSpec.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ class SdkmanCliDownloadServiceSpec : ShouldSpec({
7777
should("return InvalidVersion error for empty version") {
7878
val result = underTest.downloadSdkmanCli("install", "", "linuxx64")
7979

80-
// TODO: change error message to [empty/blank]
81-
result shouldBeLeft VersionError.InvalidVersion("")
80+
result shouldBeLeft VersionError.InvalidVersion("[empty/blank]")
8281
}
8382

8483
should("return InvalidVersion error for blank version") {
8584
val result = underTest.downloadSdkmanCli("install", " ", "linuxx64")
8685

87-
// TODO: change error message to [empty/blank]
88-
result shouldBeLeft VersionError.InvalidVersion(" ")
86+
result shouldBeLeft VersionError.InvalidVersion("[empty/blank]")
8987
}
9088
}
9189

@@ -99,8 +97,7 @@ class SdkmanCliDownloadServiceSpec : ShouldSpec({
9997
should("return InvalidPlatform error for empty platform") {
10098
val result = underTest.downloadSdkmanCli("install", "5.19.0", "")
10199

102-
// TODO: change error message to [empty/blank]
103-
result shouldBeLeft VersionError.InvalidPlatform("")
100+
result shouldBeLeft VersionError.InvalidPlatform("[empty/blank]")
104101
}
105102
}
106103

0 commit comments

Comments
 (0)