This repository was archived by the owner on Jul 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
handle errors on local particle call #25
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,8 +79,15 @@ export class ParticleProcessor { | |
|
|
||
| async executeLocalParticle(particle: ParticleDto) { | ||
| this.strategy?.onLocalParticleRecieved(particle); | ||
| await this.handleParticle(particle).catch((err) => { | ||
| log.error('particle processing failed: ' + err); | ||
| return new Promise((resolve, reject) => { | ||
| const resolveCallback = function () { | ||
| resolve() | ||
| } | ||
| const rejectCallback = function (err: any) { | ||
| reject(err) | ||
| } | ||
| // we check by callbacks that the script passed through the interpreter without errors | ||
| this.handleParticle(particle, resolveCallback, rejectCallback) | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -143,8 +150,10 @@ export class ParticleProcessor { | |
|
|
||
| /** | ||
| * Pass a particle to a interpreter and send a result to other services. | ||
| * `resolve` will be completed if ret_code equals 0 | ||
| * `reject` will be completed if ret_code not equals 0 | ||
| */ | ||
| private async handleParticle(particle: ParticleDto): Promise<void> { | ||
| private async handleParticle(particle: ParticleDto, resolve?: () => void, reject?: (r: any) => any): Promise<void> { | ||
| // if a current particle is processing, add new particle to the queue | ||
| if (this.getCurrentParticleId() !== undefined && this.getCurrentParticleId() !== particle.id) { | ||
| this.enqueueParticle(particle); | ||
|
|
@@ -160,6 +169,7 @@ export class ParticleProcessor { | |
| let actualTtl = particle.timestamp + particle.ttl - now; | ||
| if (actualTtl <= 0) { | ||
| this.strategy?.onParticleTimeout(particle, now); | ||
| if (reject) reject(`Particle expired. Now: ${now}, ttl: ${particle.ttl}, ts: ${particle.timestamp}`) | ||
| } else { | ||
| // if there is no subscription yet, previous data is empty | ||
| let prevData: Uint8Array = Buffer.from([]); | ||
|
|
@@ -191,6 +201,26 @@ export class ParticleProcessor { | |
| if (stepperOutcome.next_peer_pks.length > 0) { | ||
| this.strategy.sendParticleFurther(newParticle); | ||
| } | ||
|
|
||
| if (stepperOutcome.ret_code == 0) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably write something like this |
||
| if (resolve) { | ||
| resolve() | ||
| } | ||
| } else { | ||
| const error = stepperOutcome.error_message; | ||
| if (reject) { | ||
| reject(error); | ||
| } else { | ||
| log.error("Unhandled error: ", error); | ||
| } | ||
| } | ||
| } | ||
| } catch (e) { | ||
| if (reject) { | ||
| reject(e); | ||
| } else { | ||
| log.error("Unhandled error: ", e) | ||
| throw e; | ||
| } | ||
| } finally { | ||
| // get last particle from the queue | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can drop this fetch line completely. Public fetch api works differently (see api.ts file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just a little bit of legacy left after FOSDEM preparations