perspective-dev/perspective · error · TypeError
TileSourceSpec. must be a non-empty string
Error message
TileSourceSpec.${key} must be a non-empty string What it means
Generic string-field guard inside parseTileSourceSpec: the local helper str(key) throws this TypeError whenever a required string field (id, label, template, or attribution) of the tile source spec is missing, not a string, or an empty string. The interpolated key identifies which field failed.
Solutions
- Supply a non-empty string for the field named in the message
- Check for undefined fields from incomplete JSON definitions of the tile source
- Default-check required fields before calling registerTileSource
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/viewer-charts/src/ts/map/tile-source.ts:138 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of perspective-dev/perspective@11c8238c0c (2026-09-09).
Data as JSON: /api/errors/3bc5063d12c92eb0.
Report an issue: GitHub.
Appendix: source
Thrown at packages/viewer-charts/src/ts/map/tile-source.ts:138
/** See {@link TileSource.maxZoom}. Default 19. */
readonly max_zoom: number;
}
/**
* Validate + normalize an untrusted spec (a JSON entry or a
* `registerTileSource` argument). Throws `TypeError` naming the
* offending field; returns a frozen spec with defaults applied.
*/
export function parseTileSourceSpec(input: unknown): TileSourceSpec {
if (typeof input !== "object" || input === null) {
throw new TypeError("TileSourceSpec must be an object");
}
const raw = input as Record<string, unknown>;
const str = (key: string): string => {
const v = raw[key];
if (typeof v !== "string" || v.length === 0) {
throw new TypeError(
`TileSourceSpec.${key} must be a non-empty string`,
);
}
return v;
};
const id = str("id");
const label = str("label");
const template = str("template");
const attribution = str("attribution");
for (const placeholder of ["{z}", "{x}", "{y}"]) {
if (!template.includes(placeholder)) {
throw new TypeError(
`TileSourceSpec.template must contain "${placeholder}"`,
);
}
}View on GitHub (pinned to 11c8238c0c)