(core) Exposing more descriptive errors from exports

Summary:
Exports used to show generic message on error.
Adding error description to the message.

Test Plan: Updated tests

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3157
This commit is contained in:
Jarosław Sadziński
2021-11-29 21:12:45 +01:00
parent 90fdb55bfd
commit 53bdd6c8e1
11 changed files with 75 additions and 93 deletions

View File

@@ -215,16 +215,16 @@ export function optStringParam(p: any): string|undefined {
return undefined;
}
export function stringParam(p: any, allowed?: string[]): string {
if (typeof p !== 'string') { throw new Error(`parameter should be a string: ${p}`); }
if (allowed && !allowed.includes(p)) { throw new Error(`parameter ${p} should be one of ${allowed}`); }
export function stringParam(p: any, name: string, allowed?: string[]): string {
if (typeof p !== 'string') { throw new Error(`${name} parameter should be a string: ${p}`); }
if (allowed && !allowed.includes(p)) { throw new Error(`${name} parameter ${p} should be one of ${allowed}`); }
return p;
}
export function integerParam(p: any): number {
export function integerParam(p: any, name: string): number {
if (typeof p === 'number') { return Math.floor(p); }
if (typeof p === 'string') { return parseInt(p, 10); }
throw new Error(`parameter should be an integer: ${p}`);
throw new Error(`${name} parameter should be an integer: ${p}`);
}
export function optIntegerParam(p: any): number|undefined {