Slightly improve error path readability.
This commit is contained in:
+20
-2
@@ -250,6 +250,21 @@ export class FrigateCard extends LitElement {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected _getParseErrorPathString(path: (string|number)[]): string {
|
||||||
|
let out = '';
|
||||||
|
for (let i = 0; i < path.length; i++) {
|
||||||
|
const item = path[i];
|
||||||
|
if (typeof item == 'number') {
|
||||||
|
out += '[' + item + ']';
|
||||||
|
} else if (out) {
|
||||||
|
out += " -> " + item;
|
||||||
|
} else {
|
||||||
|
out = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the object configuration.
|
// Set the object configuration.
|
||||||
public setConfig(inputConfig: FrigateCardConfig): void {
|
public setConfig(inputConfig: FrigateCardConfig): void {
|
||||||
if (!inputConfig) {
|
if (!inputConfig) {
|
||||||
@@ -258,8 +273,11 @@ export class FrigateCard extends LitElement {
|
|||||||
|
|
||||||
const parseResult = frigateCardConfigSchema.safeParse(inputConfig);
|
const parseResult = frigateCardConfigSchema.safeParse(inputConfig);
|
||||||
if (!parseResult.success) {
|
if (!parseResult.success) {
|
||||||
const keys = getParseErrorKeys(parseResult.error);
|
let hint = '';
|
||||||
throw new Error(localize('error.invalid_configuration') + ': ' + keys.join(', '));
|
if (parseResult.error && parseResult.error.issues) {
|
||||||
|
hint = this._getParseErrorPathString(parseResult.error.issues[0].path);
|
||||||
|
}
|
||||||
|
throw new Error(localize('error.invalid_configuration') + (hint ? `: ${hint}` : ''));
|
||||||
}
|
}
|
||||||
const config = parseResult.data;
|
const config = parseResult.data;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user