Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Losing error_tracking_opt/error_tracking_opt_date on refresh #474

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-buttons-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

bugfix: create `reporting.toml` file in "wrangler/config" and move error reporting user decisions to new `reporting.toml`
22 changes: 7 additions & 15 deletions packages/wrangler/src/__tests__/sentry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { reportError } = jest.requireActual("../reporting");
describe("Error Reporting", () => {
runInTempDir({ homedir: "./home" });
mockConsoleMethods();
const reportingTOMLPath = ".wrangler/config/reporting.toml";

const originalTTY = process.stdout.isTTY;
beforeEach(() => {
Expand All @@ -34,10 +35,7 @@ describe("Error Reporting", () => {
await reportError(new Error("test error"), "testFalse");

const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
await fsp.readFile(
path.join(os.homedir(), ".wrangler/config/default.toml"),
"utf-8"
)
await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
);

expect(error_tracking_opt).toBe(true);
Expand All @@ -53,10 +51,7 @@ describe("Error Reporting", () => {
await reportError(new Error("test error"), "testFalse");

const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
await fsp.readFile(
path.join(os.homedir(), ".wrangler/config/default.toml"),
"utf-8"
)
await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
);

expect(error_tracking_opt).toBe(false);
Expand All @@ -73,9 +68,9 @@ describe("Error Reporting", () => {
await runWrangler();
await reportError(new Error("test error"), "testFalse");

expect(
fs.existsSync(path.join(os.homedir(), ".wrangler/config/default.toml"))
).toBe(false);
expect(fs.existsSync(path.join(os.homedir(), reportingTOMLPath))).toBe(
false
);

expect(Sentry.captureException).not.toHaveBeenCalledWith(
new Error("test error"),
Expand Down Expand Up @@ -137,10 +132,7 @@ describe("Error Reporting", () => {
await reportError(new Error("test error"), "testFalse");

const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
await fsp.readFile(
path.join(os.homedir(), ".wrangler/config/default.toml"),
"utf-8"
)
await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
);

expect(error_tracking_opt).toBe(false);
Expand Down
12 changes: 7 additions & 5 deletions packages/wrangler/src/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function appendReportingDecision(userInput: "true" | "false") {
const homePath = path.join(os.homedir(), ".wrangler/config/");
fs.mkdirSync(homePath, { recursive: true });
await appendFile(
path.join(homePath, "default.toml"),
path.join(homePath, "reporting.toml"),
`error_tracking_opt = ${userInput} # Sentry \nerror_tracking_opt_date = ${new Date().toISOString()} # Sentry Date Decision \n`,
{ encoding: "utf-8" }
);
Expand Down Expand Up @@ -97,15 +97,17 @@ export async function reportError(err: Error, origin = "") {
}

async function reportingPermission() {
if (!fs.existsSync(path.join(os.homedir(), ".wrangler/config/default.toml")))
if (
!fs.existsSync(path.join(os.homedir(), ".wrangler/config/reporting.toml"))
)
return undefined;

const defaultTOML = TOML.parse(
await readFile(path.join(os.homedir(), ".wrangler/config/default.toml"), {
const reportingTOML = TOML.parse(
await readFile(path.join(os.homedir(), ".wrangler/config/reporting.toml"), {
encoding: "utf-8",
})
);
const { error_tracking_opt } = defaultTOML as {
const { error_tracking_opt } = reportingTOML as {
error_tracking_opt: string | undefined;
};

Expand Down