Skip to content

Commit 5036aa9

Browse files
authored
Better error messages for misformed queries (#4007)
* Better error messages for misformed queries * Cater for raw function (no meta)
1 parent 3598cc2 commit 5036aa9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/types/src/primitive/StorageKey.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLat
5151
}
5252

5353
/** @internal */
54-
function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?]): Decoded {
54+
function decodeStorageKey (registry: Registry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?]): Decoded {
5555
// eslint-disable-next-line @typescript-eslint/no-use-before-define
5656
if (value instanceof StorageKey) {
5757
return {
@@ -73,6 +73,12 @@ function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEnt
7373

7474
assert(isFunction(fn), 'Expected function input for key construction');
7575

76+
if (fn.meta && fn.meta.type.isMap) {
77+
const map = fn.meta.type.asMap;
78+
79+
assert(Array.isArray(args) && args.length === map.hashers.length, () => `Expected an array of ${map.hashers.length} values as params to a Map query`);
80+
}
81+
7682
return {
7783
key: fn(...args),
7884
method: fn.method,
@@ -168,7 +174,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
168174
private _section?: string;
169175

170176
constructor (registry: Registry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?], override: Partial<StorageKeyExtra> = {}) {
171-
const { key, method, section } = decodeStorageKey(value);
177+
const { key, method, section } = decodeStorageKey(registry, value);
172178

173179
super(registry, key);
174180

0 commit comments

Comments
 (0)