From b6f221de7da9530000aef1694d5ef01d5e366c30 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Wed, 8 Jun 2022 23:51:26 -0700 Subject: [PATCH 01/10] PKG -- [fcl] Allow errors thrown from transaction status actor polling to be caught --- packages/fcl/src/transaction/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/fcl/src/transaction/index.js b/packages/fcl/src/transaction/index.js index 5a0012c64..d93643ff8 100644 --- a/packages/fcl/src/transaction/index.js +++ b/packages/fcl/src/transaction/index.js @@ -32,9 +32,7 @@ const isDiff = (cur, next) => { const HANDLERS = { [INIT]: async ctx => { - const tx = await fetchTxStatus(ctx.self()) - if (!isSealed(tx)) setTimeout(() => ctx.sendSelf(POLL), RATE) - ctx.merge(tx) + ctx.sendSelf(POLL) }, [SUBSCRIBE]: (ctx, letter) => { ctx.subscribe(letter.from) @@ -51,10 +49,10 @@ const HANDLERS = { try { tx = await fetchTxStatus(ctx.self()) } catch (e) { - console.error(e) - setTimeout(() => ctx.sendSelf(POLL), RATE) + ctx.merge({error: e}) return } + if (!isSealed(tx)) setTimeout(() => ctx.sendSelf(POLL), RATE) if (isDiff(ctx.all(), tx)) ctx.broadcast(UPDATED, tx) ctx.merge(tx) @@ -86,8 +84,9 @@ export function transaction(transactionId) { const suppress = opts.suppress || false return new Promise((resolve, reject) => { const unsub = subscribe(txStatus => { - if (txStatus.statusCode && !suppress) { - reject(txStatus.errorMessage) + console.log(txStatus) + if ((txStatus.statusCode || txStatus.error) && !suppress) { + reject(txStatus.error || txStatus.errorMessage) unsub() } else if (predicate(txStatus)) { resolve(txStatus) From 437d25673f71704058afd8aae26f23614a25b47c Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Wed, 8 Jun 2022 23:56:46 -0700 Subject: [PATCH 02/10] changeset --- .changeset/seven-shoes-sip.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/seven-shoes-sip.md diff --git a/.changeset/seven-shoes-sip.md b/.changeset/seven-shoes-sip.md new file mode 100644 index 000000000..0a6d1013e --- /dev/null +++ b/.changeset/seven-shoes-sip.md @@ -0,0 +1,5 @@ +--- +"@onflow/fcl": minor +--- + +Properly throw exceptions when polling transaction status using fcl.tx, remove retried requests as they are a redundancy implemented by @onflow/transport-http From f5b744a07d9b8c618feed4911076e2cd477d03ee Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 9 Jun 2022 00:05:12 -0700 Subject: [PATCH 03/10] Update seven-shoes-sip.md --- .changeset/seven-shoes-sip.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/seven-shoes-sip.md b/.changeset/seven-shoes-sip.md index 0a6d1013e..08d1a616f 100644 --- a/.changeset/seven-shoes-sip.md +++ b/.changeset/seven-shoes-sip.md @@ -2,4 +2,4 @@ "@onflow/fcl": minor --- -Properly throw exceptions when polling transaction status using fcl.tx, remove retried requests as they are a redundancy implemented by @onflow/transport-http +Make errors accessible to subscribers from fcl.tx polling (txStatus.error) and throw for onceSealed, onceExecuted, onceFinalized. Remove retried polling requests as they are a redundancy already implemented by @onflow/transport-http From 3cf42f527920039faf0f87b3117c5febfba664dc Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 9 Jun 2022 09:29:59 -0700 Subject: [PATCH 04/10] Update packages/fcl/src/transaction/index.js Co-authored-by: Greg Santos --- packages/fcl/src/transaction/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/fcl/src/transaction/index.js b/packages/fcl/src/transaction/index.js index d93643ff8..89f6ac3f7 100644 --- a/packages/fcl/src/transaction/index.js +++ b/packages/fcl/src/transaction/index.js @@ -84,7 +84,6 @@ export function transaction(transactionId) { const suppress = opts.suppress || false return new Promise((resolve, reject) => { const unsub = subscribe(txStatus => { - console.log(txStatus) if ((txStatus.statusCode || txStatus.error) && !suppress) { reject(txStatus.error || txStatus.errorMessage) unsub() From 77ba8fe1a5b522f024864d8d89ba7e2c5bb5f414 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 9 Jun 2022 13:03:15 -0700 Subject: [PATCH 05/10] Add error handling to util-actor --- .changeset/tender-jobs-exist.md | 5 +++++ packages/fcl/src/transaction/index.js | 9 +++++---- packages/util-actor/src/index.js | 14 +++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .changeset/tender-jobs-exist.md diff --git a/.changeset/tender-jobs-exist.md b/.changeset/tender-jobs-exist.md new file mode 100644 index 000000000..1a7683cbc --- /dev/null +++ b/.changeset/tender-jobs-exist.md @@ -0,0 +1,5 @@ +--- +"@onflow/util-actor": minor +--- + +Add error handling to actors. Second argument of callback is now an error object and errors can be thrown with ctx.error(e). diff --git a/packages/fcl/src/transaction/index.js b/packages/fcl/src/transaction/index.js index 89f6ac3f7..2366f5f16 100644 --- a/packages/fcl/src/transaction/index.js +++ b/packages/fcl/src/transaction/index.js @@ -9,6 +9,7 @@ import { INIT, SUBSCRIBE, UNSUBSCRIBE, + ERROR, } from "@onflow/util-actor" import {send as fclSend, decode, getTransactionStatus} from "@onflow/sdk" @@ -49,7 +50,7 @@ const HANDLERS = { try { tx = await fetchTxStatus(ctx.self()) } catch (e) { - ctx.merge({error: e}) + ctx.error(e) return } @@ -83,9 +84,9 @@ export function transaction(transactionId) { return function innerOnce(opts = {}) { const suppress = opts.suppress || false return new Promise((resolve, reject) => { - const unsub = subscribe(txStatus => { - if ((txStatus.statusCode || txStatus.error) && !suppress) { - reject(txStatus.error || txStatus.errorMessage) + const unsub = subscribe((txStatus, error) => { + if ((txStatus.statusCode || error) && !suppress) { + reject(error || txStatus.errorMessage) unsub() } else if (predicate(txStatus)) { resolve(txStatus) diff --git a/packages/util-actor/src/index.js b/packages/util-actor/src/index.js index 8baac95a8..4bb2df8d2 100644 --- a/packages/util-actor/src/index.js +++ b/packages/util-actor/src/index.js @@ -91,6 +91,7 @@ export const spawn = (fn, addr = null) => { mailbox: createMailbox(), subs: new Set(), kvs: {}, + error: null, } const ctx = { @@ -143,6 +144,10 @@ export const spawn = (fn, addr = null) => { key => (root.FCL_REGISTRY[addr].kvs[key] = data[key]) ) }, + error: error => { + root.FCL_REGISTRY[addr].error = error + for (let to of root.FCL_REGISTRY[addr].subs) send(to, UPDATED) + }, } if (typeof fn === "object") fn = fromHandlers(fn) @@ -170,11 +175,18 @@ export function subscriber(address, spawnFn, callback) { ctx.send(address, SUBSCRIBE) while (1) { const letter = await ctx.receive() + const error = root.FCL_REGISTRY[address].error if (letter.tag === EXIT) { ctx.send(address, UNSUBSCRIBE) return } - callback(letter.data) + if (error) { + callback(null, error) + ctx.send(address, UNSUBSCRIBE) + return + } + + callback(letter.data, null) } }) return () => send(self, EXIT) From 2b8b6f9abc2e6b1c6adb9686b1b086a9b2aa35c2 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 9 Jun 2022 17:57:14 -0700 Subject: [PATCH 06/10] Rename to fatalError --- packages/fcl/src/transaction/index.js | 3 +-- packages/util-actor/src/index.js | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/fcl/src/transaction/index.js b/packages/fcl/src/transaction/index.js index 2366f5f16..741b6532b 100644 --- a/packages/fcl/src/transaction/index.js +++ b/packages/fcl/src/transaction/index.js @@ -50,8 +50,7 @@ const HANDLERS = { try { tx = await fetchTxStatus(ctx.self()) } catch (e) { - ctx.error(e) - return + return ctx.fatalError(e) } if (!isSealed(tx)) setTimeout(() => ctx.sendSelf(POLL), RATE) diff --git a/packages/util-actor/src/index.js b/packages/util-actor/src/index.js index 4bb2df8d2..48e1494af 100644 --- a/packages/util-actor/src/index.js +++ b/packages/util-actor/src/index.js @@ -8,6 +8,7 @@ export const UPDATED = "UPDATED" export const SNAPSHOT = "SNAPSHOT" export const EXIT = "EXIT" export const TERMINATE = "TERMINATE" +export const ERROR = "ERROR" const root = (typeof self === "object" && self.self === self && self) || @@ -144,7 +145,7 @@ export const spawn = (fn, addr = null) => { key => (root.FCL_REGISTRY[addr].kvs[key] = data[key]) ) }, - error: error => { + fatalError: error => { root.FCL_REGISTRY[addr].error = error for (let to of root.FCL_REGISTRY[addr].subs) send(to, UPDATED) }, From db8716abcbee1b4912e30c48040b71f7d78228c4 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 9 Jun 2022 21:16:37 -0700 Subject: [PATCH 07/10] Update tender-jobs-exist.md --- .changeset/tender-jobs-exist.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tender-jobs-exist.md b/.changeset/tender-jobs-exist.md index 1a7683cbc..5905b6530 100644 --- a/.changeset/tender-jobs-exist.md +++ b/.changeset/tender-jobs-exist.md @@ -2,4 +2,4 @@ "@onflow/util-actor": minor --- -Add error handling to actors. Second argument of callback is now an error object and errors can be thrown with ctx.error(e). +Add error handling to actors. Second argument of callback is now an error object and fatal errors can be thrown with ctx.fatalError(e). From cbf50eab1e237f92217ca40e22bebec2e59b102d Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 14 Jun 2022 10:44:01 -0700 Subject: [PATCH 08/10] remove export const ERROR --- package-lock.json | 8 ++++---- packages/util-actor/src/index.js | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 045101b8c..9d51afbb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20843,12 +20843,12 @@ }, "packages/sdk": { "name": "@onflow/sdk", - "version": "1.0.2-alpha.0", + "version": "1.0.2-alpha.1", "license": "Apache-2.0", "dependencies": { "@onflow/config": "^1.0.1", "@onflow/rlp": "^1.0.1", - "@onflow/transport-http": "^1.3.0-alpha.0", + "@onflow/transport-http": "^1.3.0-alpha.1", "@onflow/util-actor": "^1.0.1", "@onflow/util-address": "^1.0.1", "@onflow/util-invariant": "^1.0.1", @@ -25127,7 +25127,7 @@ }, "packages/transport-http": { "name": "@onflow/transport-http", - "version": "1.3.0-alpha.0", + "version": "1.3.0-alpha.1", "license": "Apache-2.0", "dependencies": { "@onflow/util-address": "^1.0.1", @@ -41285,7 +41285,7 @@ "requires": { "@onflow/config": "^1.0.1", "@onflow/rlp": "^1.0.1", - "@onflow/transport-http": "^1.3.0-alpha.0", + "@onflow/transport-http": "^1.3.0-alpha.1", "@onflow/util-actor": "^1.0.1", "@onflow/util-address": "^1.0.1", "@onflow/util-invariant": "^1.0.1", diff --git a/packages/util-actor/src/index.js b/packages/util-actor/src/index.js index 48e1494af..d697091dd 100644 --- a/packages/util-actor/src/index.js +++ b/packages/util-actor/src/index.js @@ -8,7 +8,6 @@ export const UPDATED = "UPDATED" export const SNAPSHOT = "SNAPSHOT" export const EXIT = "EXIT" export const TERMINATE = "TERMINATE" -export const ERROR = "ERROR" const root = (typeof self === "object" && self.self === self && self) || From f90b1101cfbf9bad3d06168b43dcb8d03d2c66b8 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 14 Jun 2022 10:57:25 -0700 Subject: [PATCH 09/10] Update seven-shoes-sip.md --- .changeset/seven-shoes-sip.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/seven-shoes-sip.md b/.changeset/seven-shoes-sip.md index 08d1a616f..325f1577a 100644 --- a/.changeset/seven-shoes-sip.md +++ b/.changeset/seven-shoes-sip.md @@ -2,4 +2,4 @@ "@onflow/fcl": minor --- -Make errors accessible to subscribers from fcl.tx polling (txStatus.error) and throw for onceSealed, onceExecuted, onceFinalized. Remove retried polling requests as they are a redundancy already implemented by @onflow/transport-http +Make errors accessible to subscribers from fcl.tx polling (second argument of callback) and throw error for onceSealed, onceExecuted, onceFinalized promises. Also removed retried polling requests as they are a redundancy already implemented by @onflow/transport-http From 063e472562fe80862918e8c22a5169158217306d Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 14 Jun 2022 11:07:15 -0700 Subject: [PATCH 10/10] switch order of conditional --- packages/fcl/src/transaction/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fcl/src/transaction/index.js b/packages/fcl/src/transaction/index.js index 741b6532b..3363dd745 100644 --- a/packages/fcl/src/transaction/index.js +++ b/packages/fcl/src/transaction/index.js @@ -84,7 +84,7 @@ export function transaction(transactionId) { const suppress = opts.suppress || false return new Promise((resolve, reject) => { const unsub = subscribe((txStatus, error) => { - if ((txStatus.statusCode || error) && !suppress) { + if ((error || txStatus.statusCode) && !suppress) { reject(error || txStatus.errorMessage) unsub() } else if (predicate(txStatus)) {