Skip to content

Commit

Permalink
Catch entity state push promise exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jun 29, 2023
1 parent 31373a2 commit 6a9a01a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/bit-systems/delete-entity-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type Coroutine = Generator<Promise<void>, void, unknown>;
const END_SCALE = new Vector3().setScalar(0.001);
function* animateThenRemoveEntity(world: HubsWorld, eid: number): Coroutine {
if (hasSavedEntityState(world, eid)) {
deleteEntityState(APP.hubChannel!, world, eid);
deleteEntityState(APP.hubChannel!, world, eid).catch(console.warn);
}
addComponent(world, Deleting, eid);
const obj = world.eid2obj.get(eid)!;
Expand Down
2 changes: 1 addition & 1 deletion src/bit-systems/entity-persistence-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function* saveEntityStateJob(hubChannel: HubChannel, world: HubsWorld, eid: Enti
// Don't save entity state if this entity is no longer persistent
if (!hasSavedEntityState(world, eid)) return;

updateEntityState(hubChannel, world, eid);
updateEntityState(hubChannel, world, eid).catch(console.warn);
}

// TODO type for coroutine
Expand Down
2 changes: 1 addition & 1 deletion src/bit-systems/network-receive-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function networkReceiveSystem(world: HubsWorld) {
if (eid) {
if (hasSavedEntityState(world, eid)) {
console.warn("Received delete message for a persistent entity. Deleting its entity state...");
deleteEntityState(APP.hubChannel!, world, eid);
deleteEntityState(APP.hubChannel!, world, eid).catch(console.warn);
}
createMessageDatas.delete(eid);
world.nid2eid.delete(nid);
Expand Down
4 changes: 2 additions & 2 deletions src/bit-systems/object-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ function cloneObject(world: HubsWorld, sourceEid: EntityID) {

function handleClicks(world: HubsWorld, menu: EntityID, hubChannel: HubChannel) {
if (clicked(world, ObjectMenu.pinButtonRef[menu])) {
createEntityState(hubChannel, world, ObjectMenu.targetRef[menu]);
createEntityState(hubChannel, world, ObjectMenu.targetRef[menu]).catch(console.warn);
} else if (clicked(world, ObjectMenu.unpinButtonRef[menu])) {
deleteEntityState(hubChannel, world, ObjectMenu.targetRef[menu]);
deleteEntityState(hubChannel, world, ObjectMenu.targetRef[menu]).catch(console.warn);
} else if (clicked(world, ObjectMenu.cameraFocusButtonRef[menu])) {
console.log("Clicked focus");
} else if (clicked(world, ObjectMenu.cameraTrackButtonRef[menu])) {
Expand Down
21 changes: 13 additions & 8 deletions src/utils/entity-state-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ export async function deleteEntityState(hubChannel: HubChannel, world: HubsWorld
}

export async function loadSavedEntityStates(hubChannel: HubChannel) {
const list = await listEntityStates(hubChannel);
list.data.forEach(entityState => queueEntityStateAsMessage(entityState));
try {
const list = await listEntityStates(hubChannel);
list.data.forEach(entityState => queueEntityStateAsMessage(entityState));
} catch (e) {
console.warn(e);
}
}

function entityStateCreateMessage(eid: EntityID): CreateMessage {
Expand Down Expand Up @@ -115,8 +119,7 @@ function push(hubChannel: HubChannel, command: HubChannelCommand, payload?: HubC
hubChannel.channel.push(command, payload).receive("ok", resolve).receive("error", reject);
});
} else {
console.warn("Entity state API is inactive. Would have sent:", { command, payload });
return Promise.reject();
return Promise.reject(`Entity state API is inactive. Would have sent: ${command}, ${JSON.stringify(payload)}`);
}
}

Expand Down Expand Up @@ -176,9 +179,11 @@ function downloadAsJson(exportObj: any, exportName: string) {
}

async function downloadSavedEntityStates(hubChannel: HubChannel) {
listEntityStates(hubChannel).then(list => {
downloadAsJson(list, `hub-${hubChannel.hubId}`);
});
listEntityStates(hubChannel)
.then(list => {
downloadAsJson(list, `hub-${hubChannel.hubId}`);
})
.catch(console.warn);
}

// For debugging
Expand All @@ -197,7 +202,7 @@ function rebroadcastEntityState(hubChannel: HubChannel, entityState: EntityState
update_message: update
};
})
});
}).catch(console.warn);
}

function rewriteNidsForEntityState(entityState: EntityState) {
Expand Down

0 comments on commit 6a9a01a

Please sign in to comment.