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 message for invalid theme #1601

Merged
merged 1 commit into from
Jan 31, 2024
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 @@ -68,11 +68,18 @@ case class DefaultSettings(root: Config, config: Config) {
/** Default theme to use for the chart. */
val theme: String = config.getString("theme")

private def themeConfig(theme: String): Config = {
if (config.hasPath(theme))
config.getConfig(theme)
else
throw new IllegalArgumentException(s"invalid theme: $theme")
}

/** Default palette name to use. */
def primaryPalette(theme: String): String = config.getString(s"$theme.palette.primary")
def primaryPalette(theme: String): String = themeConfig(theme).getString("palette.primary")

/** Default palette name to use for lines with an offset. */
def offsetPalette(theme: String): String = config.getString(s"$theme.palette.offset")
def offsetPalette(theme: String): String = themeConfig(theme).getString(s"palette.offset")

/** Resolve color for a given theme. */
def resolveColor(theme: String, color: String): Color = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ class GraphUriSuite extends FunSuite {
assertEquals(cfg.flags.axes(0).newPlotDef().lower, PlotBound.AutoStyle)
}

test("invalid theme") {
val e = intercept[IllegalArgumentException] {
parseUri("/api/v1/graph?q=name,foo,:eq,:sum&theme=foo")
}
assertEquals(e.getMessage, "invalid theme: foo")
}

test("hints: none") {
val cfg = parseUri("/api/v1/graph?q=name,foo,:eq,:sum")
assertEquals(cfg.flags.hints, Set.empty[String])
Expand Down
Loading