Skip to content

Commit c9246ca

Browse files
Merge pull request #4049 from OriginTrail/fix/finalization-error-handling
Add fix for missing error
2 parents c0ce726 + 1b688d1 commit c9246ca

File tree

1 file changed

+12
-51
lines changed

1 file changed

+12
-51
lines changed

src/commands/protocols/publish/publish-finalization-command.js

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,7 @@ class PublishFinalizationCommand extends Command {
8484
const ual = this.ualService.deriveUAL(blockchain, contractAddress, id);
8585

8686
try {
87-
await this.validatePublishData(
88-
operationId,
89-
blockchain,
90-
merkleRoot,
91-
cachedMerkleRoot,
92-
byteSize,
93-
assertion,
94-
ual,
95-
);
87+
await this.validatePublishData(merkleRoot, cachedMerkleRoot, byteSize, assertion, ual);
9688
} catch (e) {
9789
this.logger.error(`Failed to validate publish data: ${e.message}`);
9890
this.operationIdService.emitChangeEvent(
@@ -173,52 +165,21 @@ class PublishFinalizationCommand extends Command {
173165
return Command.empty();
174166
}
175167

176-
async validatePublishData(
177-
operationId,
178-
blockchain,
179-
merkleRoot,
180-
cachedMerkleRoot,
181-
byteSize,
182-
assertion,
183-
ual,
184-
) {
185-
try {
186-
if (merkleRoot !== cachedMerkleRoot) {
187-
const errorMessage = `Invalid Merkle Root for Knowledge Collection: ${ual}. Received value from blockchain: ${merkleRoot}, Cached value from publish operation: ${cachedMerkleRoot}`;
188-
189-
this.logger.error(`Command error (${this.errorType}): ${errorMessage}`);
190-
191-
this.operationIdService.emitChangeEvent(
192-
OPERATION_ID_STATUS.FAILED,
193-
operationId,
194-
blockchain,
195-
);
196-
}
197-
198-
const calculatedAssertionSize = this.dataService.calculateAssertionSize(
199-
assertion.public ?? assertion,
200-
);
168+
async validatePublishData(merkleRoot, cachedMerkleRoot, byteSize, assertion, ual) {
169+
if (merkleRoot !== cachedMerkleRoot) {
170+
const errorMessage = `Invalid Merkle Root for Knowledge Collection: ${ual}. Received value from blockchain: ${merkleRoot}, Cached value from publish operation: ${cachedMerkleRoot}`;
201171

202-
if (byteSize.toString() !== calculatedAssertionSize.toString()) {
203-
const errorMessage = `Invalid Assertion Size for Knowledge Collection: ${ual}. Received value from blockchain: ${byteSize}, Calculated value: ${calculatedAssertionSize}`;
172+
throw new Error(errorMessage);
173+
}
204174

205-
this.logger.error(`Command error (${this.errorType}): ${errorMessage}`);
175+
const calculatedAssertionSize = this.dataService.calculateAssertionSize(
176+
assertion.public ?? assertion,
177+
);
206178

207-
this.operationIdService.emitChangeEvent(
208-
OPERATION_ID_STATUS.FAILED,
209-
operationId,
210-
blockchain,
211-
);
212-
}
213-
} catch (e) {
214-
this.logger.error(`Command error (${this.errorType}): ${e.message}`);
179+
if (byteSize.toString() !== calculatedAssertionSize.toString()) {
180+
const errorMessage = `Invalid Assertion Size for Knowledge Collection: ${ual}. Received value from blockchain: ${byteSize}, Calculated value: ${calculatedAssertionSize}`;
215181

216-
this.operationIdService.emitChangeEvent(
217-
OPERATION_ID_STATUS.FAILED,
218-
operationId,
219-
blockchain,
220-
);
221-
throw e;
182+
throw new Error(errorMessage);
222183
}
223184
}
224185

0 commit comments

Comments
 (0)