@0x/utils: Add more ZeroEx rich reverts.

`@0x/utils: Display revert error payload in stack traces.
This commit is contained in:
Lawrence Forman 2020-04-16 03:12:37 -04:00
parent 72908b02fe
commit 0c33aa16a1
5 changed files with 51 additions and 8 deletions

View File

@ -5,6 +5,10 @@
{ {
"note": "Add `ZeroExRevertErrors`", "note": "Add `ZeroExRevertErrors`",
"pr": 2540 "pr": 2540
},
{
"note": "Print full revert error in stack traces.",
"pr": 2540
} }
] ]
}, },

View File

@ -48,4 +48,5 @@ export const ZeroExRevertErrors = {
Common: require('./revert_errors/zero-ex/common_revert_errors'), Common: require('./revert_errors/zero-ex/common_revert_errors'),
Proxy: require('./revert_errors/zero-ex/proxy_revert_errors'), Proxy: require('./revert_errors/zero-ex/proxy_revert_errors'),
SimpleFunctionRegistry: require('./revert_errors/zero-ex/simple_function_registry_revert_errors'), SimpleFunctionRegistry: require('./revert_errors/zero-ex/simple_function_registry_revert_errors'),
Migrate: require('./revert_errors/zero-ex/migrate_revert_errors'),
}; };

View File

@ -113,7 +113,9 @@ export abstract class RevertError extends Error {
const instance = new type(); const instance = new type();
try { try {
const values = decoder(_bytes); const values = decoder(_bytes);
return _.assign(instance, { values }); _.assign(instance, { values });
instance.message = instance.toString();
return instance;
} catch (err) { } catch (err) {
throw new Error( throw new Error(
`Bytes ${_bytes} cannot be decoded as a revert error of type ${instance.signature}: ${err.message}`, `Bytes ${_bytes} cannot be decoded as a revert error of type ${instance.signature}: ${err.message}`,

View File

@ -0,0 +1,24 @@
import { RevertError } from '../../revert_error';
// tslint:disable:max-classes-per-file
export class AlreadyMigratingError extends RevertError {
constructor() {
super('AlreadyMigratingError', 'AlreadyMigratingError()', {});
}
}
export class MigrateCallFailedError extends RevertError {
constructor(target?: string, resultData?: string) {
super('MigrateCallFailedError', 'MigrateCallFailedError(address target, bytes resultData)', {
target,
resultData,
});
}
}
const types = [AlreadyMigratingError, MigrateCallFailedError];
// Register the types we've defined.
for (const type of types) {
RevertError.registerType(type);
}

View File

@ -9,12 +9,6 @@ export class NotImplementedError extends RevertError {
} }
} }
export class AlreadyBootstrappedError extends RevertError {
constructor() {
super('AlreadyBootstrappedError', 'AlreadyBootstrappedError()', {});
}
}
export class InvalidBootstrapCallerError extends RevertError { export class InvalidBootstrapCallerError extends RevertError {
constructor(caller?: string, expectedCaller?: string) { constructor(caller?: string, expectedCaller?: string) {
super('InvalidBootstrapCallerError', 'InvalidBootstrapCallerError(address caller, address expectedCaller)', { super('InvalidBootstrapCallerError', 'InvalidBootstrapCallerError(address caller, address expectedCaller)', {
@ -24,7 +18,25 @@ export class InvalidBootstrapCallerError extends RevertError {
} }
} }
const types = [AlreadyBootstrappedError, InvalidBootstrapCallerError, NotImplementedError]; export class InvalidDieCallerError extends RevertError {
constructor(caller?: string, expectedCaller?: string) {
super('InvalidDieCallerError', 'InvalidDieCallerError(address caller, address expectedCaller)', {
caller,
expectedCaller,
});
}
}
export class BootstrapCallFailedError extends RevertError {
constructor(target?: string, resultData?: string) {
super('BootstrapCallFailedError', 'BootstrapCallFailedError(address target, bytes resultData)', {
target,
resultData,
});
}
}
const types = [BootstrapCallFailedError, InvalidBootstrapCallerError, InvalidDieCallerError, NotImplementedError];
// Register the types we've defined. // Register the types we've defined.
for (const type of types) { for (const type of types) {