UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

102 lines (100 loc) 4.11 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5e8c0075-5794-5a0b-9561-d947785e9c20")}catch(e){}}(); import * as Sentry from "@sentry/node"; import { isAxiosError } from "axios"; import { BaseCommand } from "./base-command.js"; import { NotAuthorizedError } from "./not-authorized.error.js"; import { CLIError } from "@oclif/core/errors"; import { RequestExecutorError } from "@supernova-studio/client"; import { createApiClient } from "../utils/http-client.js"; import { getTargetEnv } from "./environment.js"; export class SentryCommand extends BaseCommand { constructor(argv, config) { super(argv, config); } async catch(error) { if (!(error instanceof CLIError)) { let { message } = error; if (error instanceof RequestExecutorError) { message = error.errorCode ? `${error.errorCode}: ${error.getDisplayMessage()}` : error.getDisplayMessage(); } this.logToStderr(message); } if (error.oclif) throw error; if (error instanceof NotAuthorizedError) throw error; if (isAxiosError(error)) { const captureMetadata = { code: error.code, message: error.message, response: { status: error.response?.status, data: error.response?.data, }, }; Sentry.captureMessage(`Axios error metadata: ${JSON.stringify(captureMetadata)}`); } Sentry.captureException(error); this.logToStderr(`Something went wrong. Please try again later.`); } async finally() { } static SKIP_VERSION_CHECK = new Set(["help", "login", "logout", "whoami"]); async checkCliVersion(flags) { if (!this.id || SentryCommand.SKIP_VERSION_CHECK.has(this.id)) return; let result; try { const client = await createApiClient(getTargetEnv()); const response = await client.get(`/cli/compatibility`, { params: { command: this.id, version: this.config.version, workspaceId: flags.workspaceId, designSystemId: flags.designSystemId, }, }); result = response.data.result; } catch { return; } if (result && !result.supported) { const updateInstruction = result.minVersion ? `Please update the CLI to version ${result.minVersion} or later to continue:\nnpm install -g @supernova-studio/cli@latest` : `Please update the CLI to continue:\nnpm install -g @supernova-studio/cli@latest`; this.error(result.message ? `${result.message}\n${updateInstruction}` : updateInstruction); } } async parse(options, argv) { Sentry.addBreadcrumb({ category: "command", data: { commandName: this.id, }, level: "debug", message: "Starting command parse", }); const parsed = await super.parse(options, argv); const span = Sentry.getActiveSpan(); if (span) { span.setAttributes({ args: Object.keys(parsed.args), designSystemId: parsed.flags.designSystemId, flags: Object.keys(parsed.flags), workspaceId: parsed.flags.workspaceId, }); } Sentry.addBreadcrumb({ category: "command", data: { result: "success", }, level: "debug", message: "Command parse completed", }); await this.checkCliVersion(parsed.flags); return parsed; } } //# sourceMappingURL=sentry-command.js.map //# debugId=5e8c0075-5794-5a0b-9561-d947785e9c20