Skip to content

Commit c3f6d44

Browse files
committed
update
1 parent a50315f commit c3f6d44

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

packages/cli/src/index.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ZModelLanguageMetaData } from '@zenstackhq/language';
22
import colors from 'colors';
3-
import { Command, Option } from 'commander';
3+
import { Command, CommanderError, Option } from 'commander';
44
import * as actions from './actions';
5+
import { CliError } from './cli-error';
56
import { telemetry } from './telemetry';
67
import { getVersion } from './utils/version-utils';
78

@@ -133,22 +134,28 @@ function createProgram() {
133134
}
134135

135136
async function main() {
136-
const program = createProgram();
137-
await telemetry.trackCli(() => void program.parseAsync());
138-
139137
let exitCode = 0;
140138

141-
process.on('unhandledRejection', (reason) => {
142-
if (reason instanceof Error) {
143-
telemetry.trackError(reason);
139+
const program = createProgram();
140+
program.exitOverride();
141+
142+
try {
143+
await telemetry.trackCli(async () => {
144+
await program.parseAsync();
145+
});
146+
} catch (e) {
147+
if (e instanceof CommanderError) {
148+
// ignore
149+
exitCode = e.exitCode;
150+
} else if (e instanceof CliError) {
151+
// log
152+
console.error(colors.red(e.message));
153+
exitCode = 1;
154+
} else {
155+
console.error(colors.red(`Unhandled error: ${e}`));
156+
exitCode = 1;
144157
}
145-
exitCode = 1;
146-
});
147-
148-
process.on('uncaughtException', (error) => {
149-
telemetry.trackError(error);
150-
exitCode = 1;
151-
});
158+
}
152159

153160
if (telemetry.isTracking) {
154161
// give telemetry a chance to send events before exit

packages/cli/src/telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createId } from '@paralleldrive/cuid2';
21
import { init, type Mixpanel } from 'mixpanel';
2+
import { randomUUID } from 'node:crypto';
33
import fs from 'node:fs';
44
import * as os from 'os';
55
import { TELEMETRY_TRACKING_TOKEN } from './constants';
@@ -30,7 +30,7 @@ export type TelemetryEvents =
3030
export class Telemetry {
3131
private readonly mixpanel: Mixpanel | undefined;
3232
private readonly hostId = getMachineId();
33-
private readonly sessionid = createId();
33+
private readonly sessionid = randomUUID();
3434
private readonly _os_type = os.type();
3535
private readonly _os_release = os.release();
3636
private readonly _os_arch = os.arch();

packages/cli/src/utils/machine-id-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// modified from https://github.com/automation-stack/node-machine-id
22

33
import { execSync } from 'child_process';
4-
import { createHash, randomUUID } from 'crypto';
4+
import { createHash, randomUUID } from 'node:crypto';
55

66
const { platform } = process;
77
const win32RegBinPath = {

0 commit comments

Comments
 (0)