Errors: one TableSpecError, raised early
{
"build() with no columns": "TableSpecError: a table needs at least one column: call .columns(c => [...])",
"the same key twice": "TableSpecError: column key \"wins\" appears twice",
"two titles": "TableSpecError: only one .title()",
"an unknown theme": "TableSpecError: unknown theme \"neon\"; one of sdv, sdvTeam, almanac, athletic, booktabs, broadsheet, brutalist, drench, gtutils, kenpom, midnight, ncaa, pl, savant, scoreboard, sofa, swiss, terminal, tier, tufte",
"sdvTeam without a league": "TableSpecError: sdvTeam needs options.league (e.g. { league: \"nfl\", team: \"KC\" })",
"a column the rows lack": "TableSpecError: column \"net_epa\" (kind text) is not a key of the first row; keys are team, conf, division, wins, losses, ties, pf, pa, srs_rank, qb, qb_espn_id, result_last"
}import { STANDINGS, type Standing } from "@sportsdataverse/examples/data";
import { SdvplotError } from "@sportsdataverse/sdvplot";
import { TableSpecError, defineTable } from "@sportsdataverse/sdvtables";
import { renderHTML } from "@sportsdataverse/sdvtables/html";
const caught = (f: () => unknown): string => {
try {
f();
return "no error";
} catch (e) {
if (!(e instanceof TableSpecError && e instanceof SdvplotError)) throw e;
return `${e.name}: ${e.message}`;
}
};
const t = defineTable<Standing>();
const wins = t.columns((c) => [c.int("wins")]);
// Rows read from a file are untyped; here a CSV that lost its net_epa column.
const csv: Record<string, unknown>[] = STANDINGS.map(({ net_epa: _dropped, ...rest }) => rest);
const loose = defineTable<Record<string, unknown>>();
{
"build() with no columns": caught(() => t.build()),
"the same key twice": caught(() => t.columns((c) => [c.int("wins"), c.int("wins")]).build()),
"two titles": caught(() => wins.title("a").title("b").build()),
"an unknown theme": caught(() => renderHTML(wins.theme("neon").build(), STANDINGS)),
"sdvTeam without a league": caught(() => renderHTML(wins.theme("sdvTeam").build(), STANDINGS)),
"a column the rows lack": caught(() =>
renderHTML(loose.columns((c) => [c.text("team"), c.text("net_epa")]).build(), csv),
),
};
Tags: table · errors · TableSpecError · SdvplotError. All sdvtables examples.