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: gracefully fail if we can't create ~/.wrangler/reporting.toml #578

Merged
merged 1 commit into from
Mar 13, 2022

Conversation

threepointone
Copy link
Contributor

In some scenarios (CI/CD, docker, etc), we won't have write access to ~/.wrangler. We already don't write a configuration file there if one passes a CF_API_TOKEN/CLOUDFLARE_API_TOKEN env var. This also adds a guard when writing the error reporting configuration file.

@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2022

🦋 Changeset detected

Latest commit: d66b5ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/1973896955/npm-package-wrangler-578

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/578/npm-package-wrangler-578

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/1973896955/npm-package-wrangler-578 dev path/to/script.js

@threepointone threepointone force-pushed the graceful-dot-wrangler-creation-failure branch from 9da4331 to 145c096 Compare March 11, 2022 12:03
{ title: "No", value: false },
],
initial: 2,
});

if (userInput.sentryDecision === "once") {
if (userInput.sentryDecision !== false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this felt like a bug, it wouldn't track the current error if we chose "Always"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was a bug.
If you chose Always then the error gets logged below on line 96 (original).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh huh I missed that, you're right

);
const reportingConfigLocation = path.join(homePath, "reporting.toml");
try {
if (!fs.existsSync(reportingConfigLocation)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh I might have been testing something, I suppose it's unnecessary. removing.

packages/wrangler/src/reporting.ts Show resolved Hide resolved
{ title: "No", value: false },
],
initial: 2,
});

if (userInput.sentryDecision === "once") {
if (userInput.sentryDecision !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was a bug.
If you chose Always then the error gets logged below on line 96 (original).

import os from "node:os";
import path from "path/posix";
import path from "node:path/posix";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably drop the posix here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@threepointone threepointone force-pushed the graceful-dot-wrangler-creation-failure branch from 145c096 to 807e708 Compare March 12, 2022 17:19
In some scenarios (CI/CD, docker, etc), we won't have write access to `~/.wrangler`. We already don't write a configuration file there if one passes a `CF_API_TOKEN`/`CLOUDFLARE_API_TOKEN` env var. This also adds a guard when writing the error reporting configuration file.
@threepointone threepointone force-pushed the graceful-dot-wrangler-creation-failure branch from 807e708 to d66b5ba Compare March 12, 2022 17:20
@@ -72,7 +80,7 @@ export async function reportError(err: Error, origin = "") {
message: "Would you like to submit a report when an error occurs?",
choices: [
{ title: "Always", value: true },
{ title: "Yes", value: "once" },
{ title: "Only this time", value: "once" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Only this time" is a little misleading because, to me, it suggests that we will do it this once and then never ask again...

@petebacondarwin petebacondarwin merged commit c56847c into main Mar 13, 2022
@petebacondarwin petebacondarwin deleted the graceful-dot-wrangler-creation-failure branch March 13, 2022 07:16
@github-actions github-actions bot mentioned this pull request Mar 13, 2022
@threepointone
Copy link
Contributor Author

threepointone commented Mar 13, 2022

Realising we have to do something else - in non-TTY environments, we need to not ask this question at all, since there will be no human to answer it.

@petebacondarwin
Copy link
Contributor

Aye! Of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants