lobehub/lobehub · error · Error
${path} is required for ${String(view.type)}
Error message
${path} is required for ${String(view.type)} What it means
Thrown by `validateVisualizationEncoding` during verify visualization validation when a non-`table` view is missing an `encoding` object (or its value is not an object). Every chart type except `table` requires an `encoding`. `${path}` is `visualizations[i].encoding`, and `${String(view.type)}` names the chart type so the message reads e.g. '... is required for bar-chart'.
Source
Thrown at apps/cli/src/commands/verifyHelpers.ts:226
if (
options?.styles &&
series.style !== undefined &&
!['accent', 'muted', 'primary'].includes(String(series.style))
) {
throw new Error(`${seriesPath}.style is invalid`);
}
});
};
const validateVisualizationEncoding = (
view: Record<string, unknown>,
fieldKeys: Set<string>,
index: number,
) => {
const path = `visualizations[${index}].encoding`;
if (view.type === 'table' && view.encoding === undefined) return;
const encoding = objectValue(view.encoding);
if (!encoding) throw new Error(`${path} is required for ${String(view.type)}`);
switch (view.type) {
case 'bar-chart': {
visualizationField(encoding, 'category', fieldKeys, path);
visualizationSeries(encoding, fieldKeys, path);
optionalVisualizationString(encoding, 'valueLabel', path);
break;
}
case 'heatmap': {
visualizationField(encoding, 'x', fieldKeys, path);
visualizationField(encoding, 'y', fieldKeys, path);
visualizationField(encoding, 'value', fieldKeys, path);
break;
}
case 'line-chart': {
visualizationField(encoding, 'x', fieldKeys, path);
visualizationSeries(encoding, fieldKeys, path, { styles: true });
optionalVisualizationString(encoding, 'xLabel', path);View on GitHub (pinned to 10f24d7ade)
Solutions
- Add an `encoding` object with the fields required for that chart type (see the per-type validators).
- Confirm the `type` is what you intended — if you want no encoding, use `type: 'table'`.
- Use the chart-type reference: bar-chart needs category+series, heatmap needs x/y/value, scatter-plot needs x/y, metric-comparison needs label/before/after, line-chart needs x+series.
Example fix
// before
{ "type": "heatmap" }
// -> visualizations[0].encoding is required for heatmap
// after
{ "type": "heatmap", "encoding": { "x": "model", "y": "task", "value": "score" } } Defensive patterns
Strategy: validation
Validate before calling
function assertEncodingForType(view: Record<string, unknown>, path: string) {
if (view.type === 'table' && view.encoding === undefined) return;
if (!view.encoding || typeof view.encoding !== 'object' || Array.isArray(view.encoding)) {
throw new Error(`${path} is required for ${String(view.type)}`);
}
} Type guard
const isEncodingObject = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v);
Prevention
- Always pair a chart `type` with the encoding fields it requires.
- Start from a per-type template rather than a generic stub.
- Validate the manifest with a schema discriminated on `type`.
- If you genuinely want no encoding, use `type: 'table'`.
When it happens
Trigger: Declaring `{type: 'bar-chart'}` with no `encoding`; setting `encoding: null`; `encoding: ""`; copy-pasting a `table` view (which may omit encoding) but changing the type to a chart without adding encoding.
Common situations: Starting from the table template (the only type that allows missing encoding) and switching the type; manifests assembled field-by-field where encoding was forgotten; a refactor that moved encoding under a wrong key.
Related errors
- ${path}.${key} must reference a declared dataset field
- ${path}.${key} must be a non-empty string
- ${path}.series must be a non-empty array
- ${seriesPath} must be an object
- ${seriesPath}.label must be a non-empty string
AI-assisted analysis of lobehub/lobehub@10f24d7ade (2026-08-12).
Data as JSON: /api/errors/3b18dd74d727ef69.
Report an issue: GitHub.