mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user