@ethernity-cloud/sdk-js 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -481,6 +481,40 @@ function initSwiftStreamClient() {
481
481
  return swiftStreamClient;
482
482
  }
483
483
 
484
+ // Set as soon as the enclave object exists so the top-level catch can report a
485
+ // failure result even when the throw happens deep inside execute().
486
+ let currentApp = null;
487
+
488
+ /**
489
+ * Best-effort: write a failure result so the trustedzone stops waiting.
490
+ *
491
+ * Securelock only publishes the result and its code; the trustedzone reads
492
+ * those and builds the signed transaction. Without them that wait runs to its
493
+ * timeout and the whole order stalls with no diagnosis.
494
+ *
495
+ * Guarded throughout: this runs while already handling a failure, so it must
496
+ * never throw or hang.
497
+ */
498
+ async function reportFailure(app, err) {
499
+ if (!app) {
500
+ console.log('cannot report failure: enclave died before initialization');
501
+ return;
502
+ }
503
+ try {
504
+ // Keep a specific code if one was already set (checksum mismatch, ...).
505
+ if (app.task_code === undefined || app.task_code === null || app.task_code === '') {
506
+ app.task_code = TaskStatus.SYSTEM_ERROR;
507
+ }
508
+ if (!app.task_result) {
509
+ app.task_result = `ENCLAVE ERROR: ${err && err.message ? err.message : err}`;
510
+ }
511
+ await app.saveResult();
512
+ console.log(`failure reported (task_code=${app.task_code})`);
513
+ } catch (reportErr) {
514
+ console.log('could not report the failure result:', reportErr);
515
+ }
516
+ }
517
+
484
518
  async function execute() {
485
519
  console.log('########################################');
486
520
  console.log('########################################');
@@ -494,6 +528,9 @@ async function execute() {
494
528
  const swiftStreamClient = initSwiftStreamClient();
495
529
 
496
530
  const app = new EtnySecureLock(swiftStreamClient);
531
+ // Exposed so the top-level handler can still publish a failure result if
532
+ // anything below throws (see reportFailure).
533
+ currentApp = app;
497
534
 
498
535
  // Testnet: materialize the self-signed cert/key from MR_ENCLAVE into the
499
536
  // file paths before anything reads them (harvest + decrypt). No-op on mainnet
@@ -543,5 +580,7 @@ async function execute() {
543
580
  await execute();
544
581
  } catch (e) {
545
582
  console.log(e);
583
+ await reportFailure(currentApp, e);
584
+ process.exitCode = 1;
546
585
  }
547
586
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethernity-cloud/sdk-js",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "A package to run ethernity cloud build scripts",
5
5
  "scripts": {
6
6
  "ecld-build": "cross-env node ./node_modules/@ethernity-cloud/sdk-js/build.js",
@@ -47,4 +47,4 @@
47
47
  },
48
48
  "author": "Alexandru Luca",
49
49
  "license": "AGPL-3.0"
50
- }
50
+ }