Don't log full error (#2952)

* Don't log full error

In `txwrapper` we can't always know if a payload is a signing payload or a signed tx so we first try one and then the other. When the former fails users get a scary-looking error. If upstream logs the error there's little we can do about it lest we [monkey patch `console.error`](https://github.com/paritytech/txwrapper-core/pull/22/files#diff-ea2d1c5845dd0e2fb9814e98a3464c2c63a43922983391e98fe9c20c328e979cR55) which is nasty af.

Hence this PR that removes the log here so that downstream can choose what to do with the error message.

* Add UnsafeOptions to let callers decide if they want errors logged or not

* Update packages/api-contract/src/util.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* Update packages/rpc-core/src/index.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* Update packages/rpc-core/src/index.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* Update packages/types/src/create/createType.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
This commit is contained in:
David
2020-12-16 13:12:50 +01:00
committed by GitHub
co-authored by Jaco Greeff
parent f8792e09c9
commit 62d1415d1b
3 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ type ContractEvents = 'CodeStored' | 'ContractExecution' | 'Instantiated';
type TOptions = BlueprintOptions | ContractOptions;
export function formatData (registry: Registry, data: Raw, { type }: TypeDef): Codec {
return createTypeUnsafe(registry, type, [data], true);
return createTypeUnsafe(registry, type, [data], { isPedantic: true });
}
export function applyOnEvent <T> (result: SubmittableResult, type: ContractEvents, fn: (records: EventRecord[]) => T): T | undefined {
+2 -2
View File
@@ -468,7 +468,7 @@ export class RpcCore implements RpcInterface {
if (!isEmpty) {
try {
inner = createTypeUnsafe(registry, type, [input], true);
inner = createTypeUnsafe(registry, type, [input], { isPedantic: true });
} catch (error) {
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}`, (error as Error).message);
}
@@ -484,7 +484,7 @@ export class RpcCore implements RpcInterface {
? hexToU8a(meta.fallback.toHex())
: undefined
: input
], true);
], { isPedantic: true });
} catch (error) {
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}`, (error as Error).message);
+7 -2
View File
@@ -8,6 +8,11 @@ import { isU8a, logger, u8aToHex } from '@polkadot/util';
import { createClass } from './createClass';
interface UnsafeOptions {
isPedantic?: boolean;
withoutLog?: boolean;
}
const l = logger('registry');
function u8aHasValue (value: Uint8Array): boolean {
@@ -59,13 +64,13 @@ function initType<T extends Codec = Codec, K extends string = string> (registry:
// argument here can be any string, which, when it cannot parse, will yield a
// runtime error.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createTypeUnsafe<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K, params: any[] = [], isPedantic?: boolean): T {
export function createTypeUnsafe<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K, params: any[] = [], { isPedantic, withoutLog }: UnsafeOptions = {}): T {
try {
// Circle back to isPedantic when it handles all cases 100% - as of now,
// it provides false warning which is more hinderance than help
return initType(registry, createClass<T, K>(registry, type), params); // , isPedantic);
} catch (error) {
l.error(error);
!withoutLog && l.error(error);
throw new Error(`createType(${type}):: ${(error as Error).message}`);
}