Expand Call errors with actual callIndex info (#2806)

* Expand Call errors with actutl callIndex info

* Update test expectation

* casing
This commit is contained in:
Jaco Greeff
2020-10-30 10:17:19 +01:00
committed by GitHub
parent 8f00351405
commit 5c69f78676
17 changed files with 145 additions and 105 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ describe('Struct', (): void => {
u32: U32
})
)(registry, 'ABC')
).toThrowError(/Struct: cannot decode type/);
).toThrowError(/Cannot decode value/);
});
it('provides a clean toString()', (): void => {
+10 -2
View File
@@ -60,10 +60,18 @@ function decodeStructFromObject <T> (registry: Registry, Types: ConstructorDef,
? assign
: new Types[key](registry, assign);
} else {
throw new Error(`Struct: cannot decode type ${Types[key].name} with value ${JSON.stringify(value)}`);
throw new Error(`Cannot decode value ${JSON.stringify(value)}`);
}
} catch (error) {
throw new Error(`Struct: failed on '${jsonKey as string}':: ${(error as Error).message}`);
let type = Types[key].name;
try {
type = new Types[key](registry).toRawType();
} catch (error) {
// ignore
}
throw new Error(`Struct: failed on ${jsonKey as string}: ${type}:: ${(error as Error).message}`);
}
return raw;
+19 -5
View File
@@ -122,11 +122,25 @@ export default class Call extends Struct implements IMethod {
constructor (registry: Registry, value: unknown, meta?: FunctionMetadataLatest) {
const decoded = decodeCall(registry, value, meta);
super(registry, {
callIndex: CallIndex,
// eslint-disable-next-line sort-keys
args: Struct.with(decoded.argsDef)
}, decoded);
try {
super(registry, {
callIndex: CallIndex,
// eslint-disable-next-line sort-keys
args: Struct.with(decoded.argsDef)
}, decoded);
} catch (error) {
let method = 'unknown.unknown';
try {
const c = registry.findMetaCall(decoded.callIndex);
method = `${c.section}.${c.method}`;
} catch (error) {
// ignore
}
throw new Error(`Call: failed decoding ${method}:: ${(error as Error).message}`);
}
this._meta = decoded.meta;
}
+6 -6
View File
@@ -149,21 +149,19 @@ export default class StorageKey extends Bytes {
private _outputType: string;
private readonly _method?: string;
private _method?: string;
private readonly _section?: string;
private _section?: string;
constructor (registry: Registry, value?: AnyU8a | StorageKey | StorageEntry | [StorageEntry, any], override: Partial<StorageKeyExtra> = {}) {
const { key, method, section } = decodeStorageKey(value);
super(registry, key);
this._method = override.method || method;
this._section = override.section || section;
this._outputType = StorageKey.getType(value as StorageKey);
// decode the args (as applicable based on the key and the hashers, after all init)
this.setMeta(StorageKey.getMeta(value as StorageKey));
this.setMeta(StorageKey.getMeta(value as StorageKey), override.section || section, override.method || method);
}
public static getMeta (value: StorageKey | StorageEntry | [StorageEntry, any]): StorageEntryMetadataLatest | undefined {
@@ -235,8 +233,10 @@ export default class StorageKey extends Bytes {
/**
* @description Sets the meta for this key
*/
public setMeta (meta?: StorageEntryMetadataLatest): this {
public setMeta (meta?: StorageEntryMetadataLatest, section?: string, method?: string): this {
this._meta = meta;
this._method = method || this._method;
this._section = section || this._section;
if (meta) {
this._outputType = unwrapStorageType(meta.type);