Skip to content

Commit

Permalink
Merge pull request #63 from unyt-org/fix-datex-out-rejections
Browse files Browse the repository at this point in the history
Fix datex out rejections
  • Loading branch information
benStre authored Jan 24, 2024
2 parents 33cf4a9 + b125b34 commit 6f1da44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,19 +1056,25 @@ export class Runtime {
if (flood) {
this.datex_out(dxb, flood_exclude, true, source)
.then(finish)
.catch(e=>reject(e));
.catch(e => {
if (wait_for_result) reject(e);
else console.error("Error sending datex block", e);
});
}
// send to receivers
else if (to) {
//this.datex_out(dxb, to)?.catch(e=>reject(e));
// send and catch errors while sending, like NetworkError
for (const to_endpoint of to) {
// check offline status (async), immediately reject if offline
this._handleEndpointOffline(to_endpoint, reject)
if (wait_for_result) this._handleEndpointOffline(to_endpoint, reject)
// send dxb
this.datex_out(dxb, to_endpoint, undefined, source)
.then(finish)
.catch(e=>reject(e));
.catch(e => {
if (wait_for_result) reject(e);
else console.error("Error sending datex block", e);
});
}
}

Expand Down Expand Up @@ -1125,7 +1131,7 @@ export class Runtime {

logger.debug("redirect " + (ProtocolDataType[header.type]) + " " + header.sid + " > " + Runtime.valueToDatexString(header.routing.receivers) + ", ttl="+ (header.routing.ttl-1));

let res = await this.datexOut(datex, header.routing.receivers, header.sid, wait_for_result, undefined, undefined, undefined, undefined, undefined, source);
const res = await this.datexOut(datex, header.routing.receivers, header.sid, wait_for_result, undefined, undefined, undefined, undefined, undefined, source);
return res;
}

Expand Down Expand Up @@ -1852,8 +1858,10 @@ export class Runtime {
//throw e
console.error(e[1]??e)
const header = e[0];
this.handleScopeError(header, e[1]);
this.updateEndpointOnlineState(header);
if (header) {
this.handleScopeError(header, e[1]);
this.updateEndpointOnlineState(header);
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion types/addressing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class Endpoint extends Target {
try {
// ping
await Runtime.datexOut(
['"ping"', [], {sign:false, encrypt:false}],
['', [], {sign:false, encrypt:false}],
this,
undefined,
true,
Expand Down

0 comments on commit 6f1da44

Please sign in to comment.