kernel/src/err.ts

37 lines
1.2 KiB
TypeScript

// notableErrors is a persistent list of errors that should be checked after
// testing. You should only add to this array in the event of an error that
// indicates a bug with the kernel.
import { OpenQueryResponse } from "./queries.js";
const notableErrors: string[] = [];
// respondErr will send an error response to the caller that closes out the
// query for the provided nonce. The extra inputs of 'messagePortal' and
// 'isWorker' are necessary to handle the fact that the MessageEvent you get
// from a worker message is different from the MessageEvent you get from a
// window message, and also from the fact that postMessage has different
// arguments depending on whether the messagePortal is a worker or a window.
function respondErr(
event: MessageEvent,
messagePortal: any,
isWorker: boolean,
isInternal: false | ((message: OpenQueryResponse) => void),
err: string,
) {
const message = {
nonce: event.data.nonce,
method: "response",
data: {},
err,
} as OpenQueryResponse;
if (isWorker) {
messagePortal.postMessage(message);
} else if (isInternal) {
isInternal(message);
} else {
messagePortal.postMessage(message, event.origin);
}
}
export { notableErrors, respondErr };