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

Raise user error when Yarn is misconfigured #8326

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

deivid-rodriguez
Copy link
Contributor

Sometimes we'll fail to run yarn --version because yarn is misconfigured because it sets yarn-path inside .yanrc to a path that's not committed to the repo.

This seems like a user error, but I couldn't find a good fit for it among existing errors, so I created a new one.

Open to suggestions here.

@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch from 8c993fa to 060150e Compare November 7, 2023 14:27
@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review November 7, 2023 14:27
@deivid-rodriguez deivid-rodriguez requested a review from a team as a code owner November 7, 2023 14:27
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch from 060150e to f55ca51 Compare November 7, 2023 14:29
@deivid-rodriguez
Copy link
Contributor Author

This one is ready for feedback!

@Nishnha
Copy link
Member

Nishnha commented Nov 7, 2023

Does this mean that if a user sets their yarn-path and ships a yarn binary with their repo, we would use it? Does it require the insecure-external-code-execution flag?

I understand the reasoning behind capturing and raising this error, but what prevents us from still attempting the update? We could raise a warning about setting yarn-path and point the yarn-path` to our own yarn binary?

@deivid-rodriguez
Copy link
Contributor Author

I think we do, yes. We delegate to yarn, and that's how yarn works. So, I don't think any flag is needed for this behavior to be like that.

In this case, user is configuring yarn-path, but the yarn-path they are configuring is not present in the repo. So yarn complains that the configuration is broken and can't run.

Yeah, we could "ignore" this error, remove yarn-path from the configuration, and try the upgrade if that makes yarn happy. It seems overkill to me though. This is a user error and I don't think it's our job to fix it?

@Nishnha
Copy link
Member

Nishnha commented Nov 7, 2023

I think we do, yes. We delegate to yarn, and that's how yarn works. So, I don't think any flag is needed for this behavior to be like that.

In this case, user is configuring yarn-path, but the yarn-path they are configuring is not present in the repo. So yarn complains that the configuration is broken and can't run.

Yeah, we could "ignore" this error, remove yarn-path from the configuration, and try the upgrade if that makes yarn happy. It seems overkill to me though. This is a user error and I don't think it's our job to fix it?

Okay gotcha, yeah if we normally do run the yarn-path binary when it's included, then I see this as a user error too!

At first I thought we should require the insecure-external-code-execution flag to use an included yarn binary, but since the user actually ships it themselves it shouldn't be an issue?

@Nishnha
Copy link
Member

Nishnha commented Nov 7, 2023

Could we add a test by raising from the SharedHelper subprocess? The code itself LGTM though.

@deivid-rodriguez
Copy link
Contributor Author

At first I thought we should require the insecure-external-code-execution flag to use an included yarn binary, but since the user actually ships it themselves it shouldn't be an issue?

Yeah, that's my thinking too!

I'll work on a test 👍.

@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch 2 times, most recently from 31f019e to 3d8b6cf Compare November 7, 2023 21:17
Copy link
Member

@Nishnha Nishnha left a comment

Choose a reason for hiding this comment

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

I notice we don't list out what the error is explicitly but that's fine since it might also change upstream. This LGTM.

@deivid-rodriguez
Copy link
Contributor Author

deivid-rodriguez commented Nov 9, 2023

Yeah!

I was actually going to test the message, in particular, because I suspect that dependabot_tmp_dir is going to show up in the user facing message and I was not sure we want that:

def sanitize_message(message)
return message unless message.is_a?(String)
path_regex =
Regexp.escape(Utils::BUMP_TMP_DIR_PATH) + "\\/" +
Regexp.escape(Utils::BUMP_TMP_FILE_PREFIX) + "[a-zA-Z0-9-]*"
message = message.gsub(/#{path_regex}/, "dependabot_tmp_dir").strip
filter_sensitive_data(message)
end

But I decided this was good enough as is, since I was seeing different behavior depending on whether I run the code through dry-run.rb, or through the specs. I'll double check next week before deploying.

@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch 2 times, most recently from 7214306 to 46f98d3 Compare November 29, 2023 13:30
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch from 46f98d3 to 135d9d5 Compare November 29, 2023 17:27
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch 2 times, most recently from 696d099 to 202f8bb Compare November 29, 2023 21:39
@deivid-rodriguez deivid-rodriguez force-pushed the deivid-rodriguez/misconfigured-yarn branch from 202f8bb to 6be37c2 Compare November 29, 2023 22:16
@deivid-rodriguez deivid-rodriguez merged commit b3c6e75 into main Nov 29, 2023
81 checks passed
@deivid-rodriguez deivid-rodriguez deleted the deivid-rodriguez/misconfigured-yarn branch November 29, 2023 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants