Remove extra error logs, bubble trace via Error (#995)
* Remove extra error logs, bubble trace via Error * Add change to CHANGELOG * Fix MagicNumber assertion check
This commit is contained in:
@@ -7,12 +7,11 @@ import { assert } from '@polkadot/util';
|
||||
import U32 from '../primitive/U32';
|
||||
|
||||
export const MAGIC_NUMBER = new U32(0x6174656d); // `meta`, reversed for Little Endian encoding
|
||||
export const MAGIC_ERROR = -61746;
|
||||
|
||||
export default class MagicNumber extends U32 {
|
||||
constructor (value?: any) {
|
||||
super(value);
|
||||
|
||||
assert(this.eq(MAGIC_NUMBER), `MagicNumber: expected ${MAGIC_NUMBER.toHex()}, found ${this.toHex()}`, MAGIC_ERROR);
|
||||
assert(this.eq(MAGIC_NUMBER), `MagicNumber mismatch: expected ${MAGIC_NUMBER.toHex()}, found ${this.toHex()}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { isHex, hexToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { MAGIC_ERROR, MAGIC_NUMBER } from './MagicNumber';
|
||||
import { MAGIC_NUMBER } from './MagicNumber';
|
||||
import MetadataVersioned from './MetadataVersioned';
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ export default class Metadata extends MetadataVersioned {
|
||||
try {
|
||||
return new MetadataVersioned(value);
|
||||
} catch (error) {
|
||||
if (error.code !== MAGIC_ERROR) {
|
||||
if (error.message.indexOf('MagicNumber mismatch') === -1) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,13 +43,15 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
if (isHex(value)) {
|
||||
return hexToBn(value, { isLe: false, isNegative }).toString();
|
||||
} else if (isU8a(value)) {
|
||||
if (!value.length) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
try {
|
||||
// NOTE When passing u8a in (typically from decoded data), it is always Little Endian
|
||||
return u8aToBn(value.subarray(0, bitLength / 8), { isLe: true, isNegative }).toString();
|
||||
} catch (error) {
|
||||
console.error(`AbstractInt value decoding failed ${error.message}`, value);
|
||||
|
||||
return '0';
|
||||
throw new Error(`AbstractInt: failed on ${JSON.stringify(value)}:: ${error.message}`);
|
||||
}
|
||||
} else if (isString(value)) {
|
||||
return new BN(value, 10).toString();
|
||||
|
||||
@@ -113,9 +113,7 @@ export default class Struct<
|
||||
throw new Error(`Struct: cannot decode type ${Types[key].name} with value ${JSON.stringify(value)}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode Struct on key '${jsonKey}': ${error.message}`);
|
||||
|
||||
throw error;
|
||||
throw new Error(`Struct: failed on '${jsonKey}':: ${error.message}`);
|
||||
}
|
||||
|
||||
return raw;
|
||||
|
||||
@@ -44,9 +44,7 @@ export default class Tuple extends AbstractArray<Codec> {
|
||||
try {
|
||||
return new Type(value && value[index]);
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode Tuple on index ${index}`, error.message);
|
||||
|
||||
throw error;
|
||||
throw new Error(`Tuple: failed on ${index}:: ${error.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ export default function decodeU8a (u8a: Uint8Array, _types: Constructor[] | { [i
|
||||
|
||||
return [value].concat(decodeU8a(u8a.subarray(value.encodedLength), types.slice(1)));
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode Uint8Array for type '${Type.name}': ${error.message}`);
|
||||
|
||||
throw error;
|
||||
throw new Error(`U8a: failed on '${Type.name}':: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ export default class Event extends Struct {
|
||||
const index = value.subarray(0, 2);
|
||||
const DataType = EventTypes[index.toString()];
|
||||
|
||||
assert(!isUndefined(DataType), `Unable to decode event for index ${u8aToHex(index)}`);
|
||||
assert(!isUndefined(DataType), `Unable to decode ${u8aToHex(index)}`);
|
||||
|
||||
return {
|
||||
DataType,
|
||||
|
||||
Reference in New Issue
Block a user