Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
Maybe?
  • Loading branch information
backspace committed Mar 20, 2024
1 parent c2ab360 commit bec6991
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
23 changes: 8 additions & 15 deletions packages/realm-server/fastboot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type RunnerOpts,
} from '@cardstack/runtime-common/search-index';
import { JSDOM } from 'jsdom';
import * as Sentry from '@sentry/node';
import { type ErrorReporter } from '@cardstack/runtime-common/realm';

const appName = '@cardstack/host';
export async function makeFastBootIndexRunner(
Expand All @@ -16,22 +16,19 @@ export async function makeFastBootIndexRunner(
): Promise<{ getRunner: IndexRunner; distPath: string }> {
let fastboot: FastBootInstance;
let distPath: string;

let globalWithErrorReporter = global as typeof globalThis & {
__boxelErrorReporter: ErrorReporter;
};

if (typeof dist === 'string') {
distPath = dist;
fastboot = new FastBoot({
distPath,
resilient: false,
buildSandboxGlobals(defaultGlobals: any) {
let sentryScope = Sentry.getCurrentScope();
console.log('sentry scope', sentryScope);
// debugger;
console.log(
'does error reporter exist when setting up fastboot v1',
globalThis.errorReporter,
);
return Object.assign({}, defaultGlobals, {
errorReporter: globalThis.errorReporter,
__SENTRY__: globalThis.__SENTRY__,
__boxelErrorReporter: globalWithErrorReporter.__boxelErrorReporter,
URL: globalThis.URL,
Request: globalThis.Request,
Response: globalThis.Response,
Expand All @@ -47,12 +44,8 @@ export async function makeFastBootIndexRunner(
appName,
dist,
(defaultGlobals: any) => {
console.log(
'does error reporter exist when setting up fastboot v2',
globalThis.errorReporter,
);
return Object.assign({}, defaultGlobals, {
errorReporter: globalThis.errorReporter,
__boxelErrorReporter: globalWithErrorReporter.__boxelErrorReporter,
URL: globalThis.URL,
Request: globalThis.Request,
Response: globalThis.Response,
Expand Down
12 changes: 7 additions & 5 deletions packages/runtime-common/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1676,21 +1676,23 @@ function lastModifiedHeader(
) as {} | { 'last-modified': string };
}

type ErrorReporter = (error: Error) => void;
export type ErrorReporter = (error: Error) => void;

let errorReporter: ErrorReporter;
let globalWithErrorReporter = global as typeof globalThis & {
__boxelErrorReporter: ErrorReporter;
};

export function setErrorReporter(reporter: ErrorReporter) {
console.log('setting an error reporter', reporter);
globalThis.errorReporter = reporter;
globalWithErrorReporter.__boxelErrorReporter = reporter;
}

export function reportError(error: Error) {
console.log('in report error');
console.log(error);
if (globalThis.errorReporter) {
if (globalWithErrorReporter.__boxelErrorReporter) {
console.log('error reporter exists');
globalThis.errorReporter(error);
globalWithErrorReporter.__boxelErrorReporter(error);
} else {
console.log('error reporter does not exist');
}
Expand Down

0 comments on commit bec6991

Please sign in to comment.