Warnings
Elicit.js warns when a spec asks for something the chart cannot do, and the chart still draws. Each warning has a stable code, a message that names the fix, and its place in the spec. Read them in the console, or take them as records with onWarning.
API reference
setWarnings(on)
Turns warnings on or off. They are on unless process.env.NODE_ENV is "production". Each call clears the record of warnings already printed, so a spec that is still wrong warns again.
setWarnings(on: boolean) → voidonWarning(listener)
Calls listener with each warning as a record, before its console line. Return false from the listener to keep that line out of the console. A listener hears nothing while warnings are off.
onWarning((warning) => boolean | void) → unsubscribe
warning: { code, message, path?, hint, key }| Option | Type | Description |
|---|---|---|
code | WarningCode | A stable kebab-case code from the table below. |
message | string | The sentence printed after the code. It names the option, the mark and the fix. |
path | string | Where in the spec, from its root: marks[1].table, constraints[0]. Set when the library knows it: always for a spec from compile(), and for a mark, guide or constraint once the chart is built. |
hint | string | What to do, in a few words. |
key | string | What makes the warning distinct. A key warns once until setWarnings is called again. |
A function that removes the listener.
The console line
Each warning prints once, as [elicit] <code>: <message>:
[elicit] unknown-option: bar({ gapp: … }) is not an option this mark reads, so it is ignored. Mark options are: …
A warning prints again only after setWarnings is called. Warnings are off when process.env.NODE_ENV is "production"; setWarnings(true) turns them back on.
Warnings as records
onWarning hands each warning to your code as { code, message, path, hint, key }. Use it to show warnings in your own interface, to fail a test, or to send them to an agent.
import { Elicit, compile, onWarning } from "elicitjs";const seen = [];const off = onWarning((w) => {seen.push(w);return false; // keep it out of the console});compile({ marks: [{ type: "barY", gapp: 2 }] });// seen[0] → { code: "unknown-option", path: "marks[0].gapp",// hint: "Fix the spelling or remove it.", message: "bar({ gapp: … }) …", key: "opt:bar:gapp" }off();
path is set for a spec built with compile(), and for a mark, guide or constraint once the chart is built. A factory called directly in JavaScript, such as plot.barY({ gapp: 2 }), has no place in a spec yet, so its warning has no path.
Codes
| Code | Triggered by | What to do |
|---|---|---|
unknown-option | An option, spec key or channel option that nothing reads, such as barY({ gapp: 2 }) or spec.scales.z. It is ignored. | Fix the spelling, or use the option the message lists. |
invalid-value | A value an option does not take, such as ordering({ strategy: "block" }) or spec.lock: "sead". A default is used. | Use one of the values the message lists. |
ignored-option | A valid option that does nothing here, such as move({ mode: "relative" }) with a plane pick, or axes.x.grid beside your own grid. | Remove it, or change the setup the message names. |
missing-option | A required option is missing: maintainSum() with no total, plot.image() with no src. | Add the option. |
ignored-channel | A channel the mark does not draw, such as series on a bar or angle on a needle. | Remove it, or use the channel the message names. |
implicit-channel | A mark reads a column that no channel names, such as a bar's category axis with no x channel. | Name the column in channels. |
channel-form | A channel written in a form it cannot use: { value } on a category axis, { expr } outside compile(), an edit on a constant or derived channel. | Use field, value or datum as the message says. |
no-schema | data with no schema. Types and domains are inferred. | Declare the schema. The message prints one inferred from the data. |
undeclared-data | The data has a column or table the schema does not declare. | Declare it in the schema, or drop it from the data. |
unknown-column | A spec or call names a column the table does not declare: a constraint's field, chart.set(field). | Name a declared column, or declare it. |
unknown-table | A spec or call names a table the schema does not declare: a mark's or edit's table. | Name a declared table. |
schema-incomplete | A field or table lacks what a feature needs: a type, a domain, a default, a key: true column, a ref target. | Add what the message names. |
type-mismatch | A value contradicts its field's declared type. | Fix the value, or declare the type the data has. |
out-of-domain | A value outside its field's domain, in the seed rows or a write. | Widen the domain, fix the value, or declare the field open: true. |
seed-rows | Seeded rows break a declared rule: a constraint, multi: false, a reference to a missing node. They are kept. | Fix the data or the rule. |
scale-mismatch | A channel resolves to a scale kind the mark, edit or layout cannot use, such as a bar on a continuous category axis. | Declare the field's type so the right scale resolves. |
structure-mismatch | A feature needs a network or hierarchy dataset: link(), layout.network.tree(), ports. | Declare schema.structure and its tables. |
degraded-drawing | The mark draws, but not as asked: bars overlap, a layout overflows the plot, a curve falls back to straight sides. | Change the data, the size or the option the message names. |
edit-never-fires | An edit no gesture can reach, or one that can write nothing: an edit on a channel whose scale cannot invert, a pick no driver claims, create on an axis. | Move the edit to a channel or mark it can act on. |
edit-conflict | Two edits or marks compete for one gesture or column, such as a plane edit on two marks over the same rows. | Keep one, or tell them apart with when. |
write-refused | A gesture or call could not write: a closed domain is full, a constraint refused a layout. | Loosen the constraint or domain the message names. |
unknown-name | No edit, event, theme, design, icon or renderer has this name: chart.control("nope"), theme: "nope". | Use one of the names the message lists, or register it. |
bad-call | A chart, dataset or ui call got arguments or a state it cannot act on, such as a call on a destroyed chart. Nothing happened. | Call it as the message shows. |
renderer-unsupported | The renderer cannot draw what the spec asks: a shader look on SVG, overflow: "visible" on canvas. | Switch renderer, or drop the option. |
load-failed | An image or a WebGL context did not load. | Check the URL, CORS or the browser's WebGL support. |
function-threw | A function in the spec threw: a channel's fn, layout.custom. A fallback is used. | Fix the function. |
authoring | A custom mark, constraint, layout or look breaks its contract, such as a constraint that returns neither rows nor a boolean. | See Custom marks for what it must return. |