Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error for invalid stack #1251

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ case class Grapher(settings: DefaultSettings) {
.stack
.reverse
.flatMap {
case ModelExtractors.PresentationType(s) => s.perOffset
case v => throw new MatchError(v)
case ModelExtractors.PresentationType(s) =>
s.perOffset
case v =>
val tpe = v.getClass.getSimpleName
throw new IllegalArgumentException(s"expecting time series expr, found $tpe '$v'")
}
if (settings.simpleLegendsEnabled)
SimpleLegends.generate(exprs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ class GrapherSuite extends AnyFunSuite with BeforeAndAfterAll {
"/api/v1/graph?e=2012-01-01&q=name,sps,:eq,(,nf.cluster,),:by,max,2,:bottomk-others-avg&features=unstable"
}

test("invalid stuff on stack") {
val uri = "/api/v1/graph?e=2012-01-01&q=name,sps,:eq,(,nf.cluster,),:by,foo"
val e = intercept[IllegalArgumentException] {
grapher.toGraphConfig(Uri(uri)).parsedQuery.get
}
assert(e.getMessage === "expecting time series expr, found String 'foo'")
}

def renderTest(name: String)(uri: => String): Unit = {
test(name) {
val fname = Strings.zeroPad(Hash.sha1bytes(name), 40).substring(0, 8) + ".png"
Expand Down