Skip to content

Commit ad27de8

Browse files
committed
error handling on quantile values
1 parent b2efcaf commit ad27de8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

core/src/main/scala/org/apache/spark/status/api/v1/JsonRootResource.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,16 @@ private[v1] class NotFoundException(msg: String) extends WebApplicationException
140140
.entity(msg)
141141
.build()
142142
)
143+
144+
private[v1] class BadParameterException(msg: String) extends WebApplicationException(
145+
new IllegalArgumentException(msg),
146+
Response
147+
.status(Response.Status.BAD_REQUEST)
148+
.entity(msg)
149+
.build()
150+
) {
151+
def this(param: String, exp: String, actual: String) = {
152+
this("Bad value for parameter \"" + param + "\". Expected a " + exp + ", got \"" +
153+
actual + "\"")
154+
}
155+
}

core/src/main/scala/org/apache/spark/status/api/v1/OneStageResource.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,14 @@ private[v1] class OneStageResource(uiRoot: UIRoot) {
8080
stageInfo.stageId + ":" + stageInfo.attemptId)
8181
)
8282
}
83-
//TODO error handling
84-
val quantiles = quantileString.split(",").map{_.toDouble}
85-
println("quantiles = " + quantiles.mkString(","))
83+
val quantiles = quantileString.split(",").map{s =>
84+
try {
85+
s.toDouble
86+
} catch {
87+
case nfe: NumberFormatException =>
88+
throw new BadParameterException("quantiles", "double", s)
89+
}
90+
}
8691
AllStagesResource.taskMetricDistributions(stageUiData.taskData.values, quantiles)
8792
}
8893
}

0 commit comments

Comments
 (0)