Skip to content

Commit 68ac8a1

Browse files
zhaomin1423ulysses-you
authored andcommitted
[KYUUBI #2453] [Improvement] checkValue of TypedConfigBuilder shall also print the config name
### _Why are the changes needed?_ ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2465 from zhaomin1423/2453. Closes #2453 8a62499 [Min Zhao] fix tset 54ee09d [Min Zhao] fix suite 3d434a7 [Min Zhao] [KYUUBI #2453] [Improvement] checkValue of TypedConfigBuilder shall also print the config name f7c7bf2 [Min Zhao] [KYUUBI #2453] [Improvement] checkValue of TypedConfigBuilder shall also print the config name Authored-by: Min Zhao <zhaomin1423@163.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 40739a9 commit 68ac8a1

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

kyuubi-common/src/main/scala/org/apache/kyuubi/config/ConfigBuilder.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ private[kyuubi] case class TypedConfigBuilder[T](
136136
/** Checks if the user-provided value for the config matches the validator. */
137137
def checkValue(validator: T => Boolean, errMsg: String): TypedConfigBuilder[T] = {
138138
transform { v =>
139-
if (!validator(v)) throw new IllegalArgumentException(errMsg)
139+
if (!validator(v)) {
140+
throw new IllegalArgumentException(s"'$v' in ${parent.key} is invalid. $errMsg")
141+
}
140142
v
141143
}
142144
}

kyuubi-common/src/test/scala/org/apache/kyuubi/config/ConfigBuilderSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,16 @@ class ConfigBuilderSuite extends KyuubiFunSuite {
8181
val e = intercept[IllegalArgumentException](kyuubiConf.get(timeConf))
8282
assert(e.getMessage startsWith "The formats accepted are 1) based on the ISO-8601")
8383
}
84+
85+
test("invalid config") {
86+
val intConf = ConfigBuilder("kyuubi.invalid.config")
87+
.intConf
88+
.checkValue(t => t > 0, "must be positive integer")
89+
.createWithDefault(3)
90+
assert(intConf.key === "kyuubi.invalid.config")
91+
assert(intConf.defaultVal.get === 3)
92+
val kyuubiConf = KyuubiConf().set(intConf.key, "-1")
93+
val e = intercept[IllegalArgumentException](kyuubiConf.get(intConf))
94+
assert(e.getMessage equals "'-1' in kyuubi.invalid.config is invalid. must be positive integer")
95+
}
8496
}

kyuubi-common/src/test/scala/org/apache/kyuubi/service/authentication/KyuubiAuthenticationFactorySuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class KyuubiAuthenticationFactorySuite extends KyuubiFunSuite {
5858
test("AuthType Other") {
5959
val conf = KyuubiConf().set(KyuubiConf.AUTHENTICATION_METHOD, Seq("INVALID"))
6060
val e = intercept[IllegalArgumentException](new KyuubiAuthenticationFactory(conf))
61-
assert(e.getMessage === "the authentication type should be one or more of" +
61+
assert(e.getMessage contains "the authentication type should be one or more of" +
6262
" NOSASL,NONE,LDAP,KERBEROS,CUSTOM")
6363
}
6464

kyuubi-server/src/test/scala/org/apache/kyuubi/server/KyuubiServerSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class KyuubiServerSuite extends KyuubiFunSuite {
9292
test("invalid port") {
9393
val conf = KyuubiConf().set(KyuubiConf.FRONTEND_THRIFT_BINARY_BIND_PORT, 100)
9494
val e = intercept[IllegalArgumentException](new KyuubiServer().initialize(conf))
95-
assert(e.getMessage === "Invalid Port number")
95+
assert(e.getMessage contains "Invalid Port number")
9696
}
9797

9898
test("invalid zookeeper quorum") {

0 commit comments

Comments
 (0)