Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 web err stack update #615

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions binding/web/src/rhino_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class RhinoWorker {
break;
case 'failed':
case 'error':
const error = pvStatusToException(ev.data.status, ev.data.message);
const error = pvStatusToException(ev.data.status, ev.data.shortMessage, ev.data.messageStack);
if (processErrorCallback) {
processErrorCallback(error);
} else {
Expand All @@ -197,7 +197,7 @@ export class RhinoWorker {
break;
case 'failed':
case 'error':
const error = pvStatusToException(event.data.status, event.data.message);
const error = pvStatusToException(event.data.status, event.data.shortMessage, event.data.messageStack);
reject(error);
break;
default:
Expand Down Expand Up @@ -271,7 +271,7 @@ export class RhinoWorker {
break;
case 'failed':
case 'error':
const error = pvStatusToException(event.data.status, event.data.message);
const error = pvStatusToException(event.data.status, event.data.shortMessage, event.data.messageStack);
reject(error);
break;
default:
Expand Down
14 changes: 8 additions & 6 deletions binding/web/src/rhino_worker_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function processErrorCallback(error: RhinoError): void {
self.postMessage({
command: 'error',
status: error.status,
message: error.message,
shortMessage: error.shortMessage,
messageStack: error.messageStack
});
}

Expand All @@ -44,7 +45,7 @@ self.onmessage = async function (
self.postMessage({
command: 'error',
status: PvStatus.INVALID_STATE,
message: 'Rhino already initialized',
shortMessage: 'Rhino already initialized',
});
return;
}
Expand All @@ -71,7 +72,8 @@ self.onmessage = async function (
self.postMessage({
command: 'error',
status: PvStatus.RUNTIME_ERROR,
message: e.message,
shortMessage: e.shortMessage,
messageStack: e.messageStack
});
}
break;
Expand All @@ -80,7 +82,7 @@ self.onmessage = async function (
self.postMessage({
command: 'error',
status: PvStatus.INVALID_STATE,
message: 'Rhino not initialized',
shortMessage: 'Rhino not initialized',
});
return;
}
Expand All @@ -91,7 +93,7 @@ self.onmessage = async function (
self.postMessage({
command: 'error',
status: PvStatus.INVALID_STATE,
message: 'Rhino not initialized',
shortMessage: 'Rhino not initialized',
});
return;
}
Expand All @@ -115,7 +117,7 @@ self.onmessage = async function (
command: 'failed',
status: PvStatus.RUNTIME_ERROR,
// @ts-ignore
message: `Unrecognized command: ${event.data.command}`,
shortMessage: `Unrecognized command: ${event.data.command}`,
});
}
};
3 changes: 2 additions & 1 deletion binding/web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export type RhinoWorkerRequest =
export type RhinoWorkerFailureResponse = {
command: 'failed' | 'error';
status: PvStatus;
message: string;
shortMessage: string;
messageStack: string[];
};

export type RhinoWorkerInitResponse =
Expand Down
10 changes: 6 additions & 4 deletions binding/web/test/rhino.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe("Rhino Binding", function () {
});

it(`should return correct error message stack (${instanceString})`, async () => {
let firstError = "";
let messageStack = [];
try {
const rhino = await instance.create(
"invalidAccessKey",
Expand All @@ -264,10 +264,12 @@ describe("Rhino Binding", function () {
);
expect(rhino).to.be.undefined;
} catch (e: any) {
firstError = e.message;
expect(firstError.length).to.be.lt(1024);
messageStack = e.messageStack;
}

expect(messageStack.length).to.be.gt(0);
expect(messageStack.length).to.be.lte(8);

try {
const rhino = await instance.create(
"invalidAccessKey",
Expand All @@ -277,7 +279,7 @@ describe("Rhino Binding", function () {
);
expect(rhino).to.be.undefined;
} catch (e: any) {
expect(firstError.length).to.be.eq(e.message.length);
expect(messageStack.length).to.be.eq(e.messageStack.length);
}
});
}
Expand Down