Skip to content

Commit

Permalink
fix sentry errors not being reported to sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
jaerod95 committed May 7, 2024
1 parent 3bd2af5 commit e6ebc94
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/add-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const addProject = async () => {
`\nSorry, there was an error adding a project to your workspace: `,
error
);
quit("Project selection was not updated.");
await quit("Project selection was not updated.");
}
};

Expand Down
12 changes: 5 additions & 7 deletions lib/ditto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import fs from "fs";
import path from "path";
import * as Sentry from "@sentry/node";
import { version as release } from "../package.json";

import { init, needsTokenOrSource } from "./init/init";
import { pull } from "./pull";
import { quit } from "./utils/quit";
import addProject from "./add-project";
import removeProject from "./remove-project";
import { replace } from "./replace";
import { generateSuggestions } from "./generate-suggestions";

import processMetaOption from "./utils/processMetaOption";
import { importComponents } from "./importComponents";
import { showComponentFolders } from "./component-folders";
Expand Down Expand Up @@ -165,7 +163,7 @@ const setupCommands = () => {
} else {
cmd.option(flags, description);
}
},
}
);
}

Expand All @@ -190,14 +188,14 @@ const setupCommands = () => {
const setupOptions = () => {
program.option(
"-m, --meta <data...>",
"Include arbitrary data in requests to the Ditto API. Ex: -m githubActionRequest:true trigger:manual",
"Include arbitrary data in requests to the Ditto API. Ex: -m githubActionRequest:true trigger:manual"
);
program.version(VERSION, "-v, --version", "Output the current version");
};

const executeCommand = async (
command: Command | "none",
options: any,
options: any
): Promise<void> => {
const needsInitialization =
CONFIG_FILE_RELIANT_COMMANDS.includes(command) && needsTokenOrSource();
Expand All @@ -206,7 +204,7 @@ const executeCommand = async (
try {
await init();
} catch (error) {
quit("Exiting Ditto CLI...");
await quit("Exiting Ditto CLI...");
return;
}
}
Expand Down Expand Up @@ -266,7 +264,7 @@ const executeCommand = async (
});
}
default: {
quit("Exiting Ditto CLI...");
await quit("Exiting Ditto CLI...");
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const init = async () => {
} = config.parseSourceInformation();

if (hasTopLevelProjectsField) {
return quit(`${output.errorText(
return await quit(`${output.errorText(
`Support for ${output.warnText(
"projects"
)} as a top-level field has been removed; please configure ${output.warnText(
Expand All @@ -51,7 +51,7 @@ See ${output.url("https://github.com/dittowords/cli")} for more information.`);
}

if (hasTopLevelComponentsField) {
return quit(
return await quit(
`${output.errorText(
"Support for `components` as a top-level field has been removed; please configure `sources.components` instead."
)}
Expand Down
4 changes: 2 additions & 2 deletions lib/init/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const collectAndSaveSource = async (
const token = config.getToken(consts.CONFIG_FILE, consts.API_HOST);
const project = await collectSource(token, components);
if (!project) {
quit(null, 0);
await quit(null, 0);
return;
}

Expand All @@ -126,7 +126,7 @@ export const collectAndSaveSource = async (
await askForAnotherToken();
await collectAndSaveSource({ components });
} else {
quit(null, 2);
await quit(null, 2);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/init/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ export const collectAndSaveToken = async (message: string | null = null) => {
// https://github.com/enquirer/enquirer/issues/225#issue-516043136
// Empty string corresponds to the user hitting Ctrl + C
if (error === "") {
quit("", 0);
await quit("", 0);
return;
}

const eventId = Sentry.captureException(error);
const eventStr = `\n\nError ID: ${output.info(eventId)}`;

return quit(
return await quit(
output.errorText(
"Something went wrong. Please contact support or try again later."
) + eventStr
Expand Down
5 changes: 2 additions & 3 deletions lib/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ export const pull = async (options?: PullOptions) => {
const includeSampleData = options?.includeSampleData || false;
const token = config.getToken(consts.CONFIG_FILE, consts.API_HOST);
const sourceInformation = config.parseSourceInformation();

try {
return await downloadAndSave(sourceInformation, token, {
meta,
Expand All @@ -598,14 +597,14 @@ export const pull = async (options?: PullOptions) => {
const eventId = Sentry.captureException(e);
const eventStr = `\n\nError ID: ${output.info(eventId)}`;
if (e instanceof AxiosError) {
return quit(
return await quit(
output.errorText(
"Something went wrong connecting to Ditto servers. Please contact support or try again later."
) + eventStr
);
}

return quit(
return await quit(
output.errorText(
"Something went wrong. Please contact support or try again later."
) + eventStr
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/quit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export function quit(message: string | null, exitCode = 2) {
import * as Sentry from "@sentry/node";

export async function quit(message: string | null, exitCode = 2) {
if (message) console.log(`\n${message}\n`);
await Sentry.flush();
process.exit(exitCode);
}

0 comments on commit e6ebc94

Please sign in to comment.