Deupe decodeU8a result format on failure (#5076)
This commit is contained in:
@@ -6,7 +6,7 @@ import type { Codec, CodecClass, Registry } from '../types';
|
|||||||
import { u8aToHex } from '@polkadot/util';
|
import { u8aToHex } from '@polkadot/util';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
function formatFailure (registry: Registry, { message }: Error, u8a: Uint8Array, i: number, count: number, Type: CodecClass, key?: string): string {
|
function formatFailure (registry: Registry, result: unknown[], { message }: Error, u8a: Uint8Array, i: number, count: number, Type: CodecClass, key?: string): string {
|
||||||
let type = '';
|
let type = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -15,6 +15,8 @@ function formatFailure (registry: Registry, { message }: Error, u8a: Uint8Array,
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.error(JSON.stringify(result, null, 2));
|
||||||
|
|
||||||
return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,9 +44,7 @@ export function decodeU8a <T extends Codec = Codec> (registry: Registry, result:
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.error(JSON.stringify(result, null, 2));
|
throw new Error(formatFailure(registry, result, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
||||||
|
|
||||||
throw new Error(formatFailure(registry, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [result, offset];
|
return [result, offset];
|
||||||
@@ -70,9 +70,7 @@ export function decodeU8aStruct (registry: Registry, result: [string, Codec][],
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.error(JSON.stringify(result, null, 2));
|
throw new Error(formatFailure(registry, result, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
||||||
|
|
||||||
throw new Error(formatFailure(registry, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [result, offset];
|
return [result, offset];
|
||||||
@@ -98,9 +96,7 @@ export function decodeU8aVec <T extends Codec = Codec> (registry: Registry, resu
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(JSON.stringify(result, null, 2));
|
throw new Error(formatFailure(registry, result, error as Error, u8a.subarray(offset), i, count, Type));
|
||||||
|
|
||||||
throw new Error(formatFailure(registry, error as Error, u8a.subarray(offset), i, count, Type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [offset, offset - startAt];
|
return [offset, offset - startAt];
|
||||||
|
|||||||
Reference in New Issue
Block a user