dongjoon-hyun commented on code in PR #50729: URL: https://github.com/apache/spark/pull/50729#discussion_r2062502038
########## common/utils/src/main/scala/org/apache/spark/internal/config/ConfigBuilder.scala: ########## @@ -74,29 +69,68 @@ private object ConfigHelpers { v.map(stringConverter).mkString(",") } - def timeFromString(str: String, unit: TimeUnit): Long = JavaUtils.timeStringAs(str, unit) + def timeFromString(str: String, unit: TimeUnit, key: String): Long = { + try { + JavaUtils.timeStringAs(str, unit) + } catch { + case _: NumberFormatException => throw configTypeMismatchError(key, str, s"time in $unit") + } + } def timeToString(v: Long, unit: TimeUnit): String = s"${TimeUnit.MILLISECONDS.convert(v, unit)}ms" - def byteFromString(str: String, unit: ByteUnit): Long = { - val (input, multiplier) = - if (str.length() > 0 && str.charAt(0) == '-') { - (str.substring(1), -1) - } else { - (str, 1) - } - multiplier * JavaUtils.byteStringAs(input, unit) + def byteFromString(str: String, unit: ByteUnit, key: String): Long = { + try { + val (input, multiplier) = + if (str.nonEmpty && str.charAt(0) == '-') { + (str.substring(1), -1) + } else { + (str, 1) + } + multiplier * JavaUtils.byteStringAs(input, unit) + } catch { + case _: NumberFormatException => + throw configTypeMismatchError(key, str, s"bytes in $unit") + } } def byteToString(v: Long, unit: ByteUnit): String = s"${unit.convertTo(v, ByteUnit.BYTE)}b" def regexFromString(str: String, key: String): Regex = { try str.r catch { - case e: PatternSyntaxException => - throw new IllegalArgumentException(s"$key should be a regex, but was $str", e) + case _: PatternSyntaxException => throw configTypeMismatchError(key, str, "regex") } } + def configTypeMismatchError( + key: String, value: String, configType: String): SparkIllegalArgumentException = { + new SparkIllegalArgumentException( Review Comment: indentation? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org