Skip to content

Commit

Permalink
Add more info to operation estimation errors in batches (#2797)
Browse files Browse the repository at this point in the history
It allows to find the faulty operation
Otherwise, it's just random guessing why it failed

Co-authored-by: Sergey Kintsel <[email protected]>
  • Loading branch information
sergey-kintsel and serjonya-trili authored Jan 17, 2024
1 parent 16d75a1 commit b1e7e68
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
5 changes: 1 addition & 4 deletions packages/taquito/src/contract/lambda-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export default class LambdaView {
await this.lambdaContract.methods.default(this.voidLambda).send();
} catch (ex) {
if (ex instanceof TezosOperationError) {
const lastError: any = ex.errors[ex.errors.length - 1];

const failedWith = lastError.with;
return failedWith;
return (ex.lastError as any).with;
} else {
throw ex;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/taquito/src/estimate/rpc-estimate-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ export class RPCEstimateProvider extends Provider implements EstimationProvider

// Fail early in case of errors
if (errors.length) {
throw new TezosOperationError(errors, 'Error occurred during estimation');
throw new TezosOperationError(
errors,
'Error occurred during estimation',
opResponse.contents
);
}

let numberOfOps = 1;
Expand Down
30 changes: 18 additions & 12 deletions packages/taquito/src/operations/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ParameterValidationError, RpcError, TaquitoError } from '@taquito/core';
import {
MichelsonV1ExpressionBase,
OperationContentsAndResult,
OperationResult,
OperationResultDelegation,
OperationResultOrigination,
Expand Down Expand Up @@ -33,32 +34,37 @@ const isErrorWithMessage = (error: any): error is TezosOperationErrorWithMessage
* @description Generic tezos error that will be thrown when a mistake occurs when doing an operation; more details here https://tezos.gitlab.io/api/errors.html
*/
export class TezosOperationError extends RpcError {
id: string;
kind: string;
public readonly lastError: TezosGenericOperationError;

constructor(
public readonly errors: TezosGenericOperationError[],
public readonly errorDetails?: string
public readonly errorDetails: string,
public readonly operationsWithResults: OperationContentsAndResult[]
) {
super();
this.name = 'TezosOperationError';
// Last error is 'often' the one with more detail
const lastError = errors[errors.length - 1];
this.id = lastError.id;
this.kind = lastError.kind;
this.lastError = errors[errors.length - 1];

this.message = `(${this.kind}) ${this.id}`;

if (isErrorWithMessage(lastError)) {
if (lastError.with.string) {
this.message = lastError.with.string;
} else if (lastError.with.int) {
this.message = lastError.with.int;
if (isErrorWithMessage(this.lastError)) {
if (this.lastError.with.string) {
this.message = this.lastError.with.string;
} else if (this.lastError.with.int) {
this.message = this.lastError.with.int;
} else {
this.message = JSON.stringify(lastError.with);
this.message = JSON.stringify(this.lastError.with);
}
}
}

get id(): string {
return this.lastError.id;
}
get kind(): string {
return this.lastError.kind;
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/taquito/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export abstract class Provider {
if (errors.length) {
throw new TezosOperationError(
errors,
'Error occurred during validation simulation of operation'
'Error occurred during validation simulation of operation',
opResponse
);
}

Expand Down

0 comments on commit b1e7e68

Please sign in to comment.