-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpre-start.ts
More file actions
54 lines (43 loc) · 1.6 KB
/
pre-start.ts
File metadata and controls
54 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'dotenv/config';
import { getTelemetry } from '~/lib/telemetry/telemetry-manager';
import { TelemetryEventType } from '~/lib/telemetry/telemetry-types';
import { normalizeError } from '~/lib/telemetry/error-utils';
import { execSync } from 'child_process';
const runApp = async (): Promise<void> => {
// Run migrations first
execSync('tsx run-migrations.ts', { stdio: 'inherit' });
// Setup tunnel if in local environment
if (process.env.NEXT_PUBLIC_ENV_NAME === 'local') {
execSync('tsx setup-tunnel.ts', { stdio: 'inherit' });
}
console.log('⏳ Please wait until the URL appears here');
console.log('★═══════════════════════════════════════★');
};
async function trackAppError(error: any) {
const telemetry = await getTelemetry();
try {
const errorInfo = normalizeError(error);
await telemetry.trackTelemetryEvent({
eventType: TelemetryEventType.APP_ERROR,
properties: {
errorMessage: errorInfo.message,
error: errorInfo,
},
});
telemetry.shutdown();
// Leave some time for telemetry to flush the event before the process exits
await new Promise((resolve) => setTimeout(resolve, 2000));
} catch (telemetryError) {
console.warn('Failed to track start error:', (telemetryError as Error).message);
}
}
// Add error handling for the entire runApp function
const runAppWithErrorHandling = async (): Promise<void> => {
try {
await runApp();
} catch (error) {
await trackAppError(error);
process.exit(1);
}
};
runAppWithErrorHandling();