From dc7b8d2ad152780e847ab597d40a57f13ab86d4f Mon Sep 17 00:00:00 2001 From: "S.Sandhu" <167903774+sachin-sandhu@users.noreply.github.com> Date: Sat, 31 Aug 2024 00:20:31 -0400 Subject: [PATCH] Fixes Yarn Dependabot::SharedHelpers::HelperSubprocessFailed issues --- npm_and_yarn/lib/dependabot/npm_and_yarn.rb | 7 ++++-- .../npm_and_yarn/yarn_error_handler_spec.rb | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn.rb index b500637009c..4cadade7fa0 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn.rb @@ -90,6 +90,8 @@ module NpmAndYarn PACKAGE_NOT_FOUND_PACKAGE_NAME_CAPTURE_SPLIT_REGEX = /(?<=\w)\@/ YARN_PACKAGE_NOT_FOUND_CODE = /npm package "(?.*)" does not exist under owner "(?.*)"/ + YARN_PACKAGE_NOT_FOUND_CODE_1 = /Couldn't find package "[^@].*(?.*)" on the "(?.*)" registry./ + YARN_PACKAGE_NOT_FOUND_CODE_2 = /Couldn't find package "[^@].*(?.*)" required by "(?.*)" on the "(?.*)" registry./ # rubocop:disable Layout/LineLength YN0035 = T.let({ PACKAGE_NOT_FOUND: %r{(?@[\w-]+\/[\w-]+@\S+): Package not found}, @@ -529,9 +531,10 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock) matchfn: nil }, { - patterns: [YARN_PACKAGE_NOT_FOUND_CODE], + patterns: [YARN_PACKAGE_NOT_FOUND_CODE, YARN_PACKAGE_NOT_FOUND_CODE_1, YARN_PACKAGE_NOT_FOUND_CODE_2], handler: lambda { |message, _error, _params| - msg = message.match(YARN_PACKAGE_NOT_FOUND_CODE) + msg = message.match(YARN_PACKAGE_NOT_FOUND_CODE) || message.match(YARN_PACKAGE_NOT_FOUND_CODE_1) || + message.match(YARN_PACKAGE_NOT_FOUND_CODE_2) Dependabot::DependencyFileNotResolvable.new(msg) }, diff --git a/npm_and_yarn/spec/dependabot/npm_and_yarn/yarn_error_handler_spec.rb b/npm_and_yarn/spec/dependabot/npm_and_yarn/yarn_error_handler_spec.rb index 64a15445390..5aa9c672a10 100644 --- a/npm_and_yarn/spec/dependabot/npm_and_yarn/yarn_error_handler_spec.rb +++ b/npm_and_yarn/spec/dependabot/npm_and_yarn/yarn_error_handler_spec.rb @@ -741,6 +741,31 @@ end end + context "when the error message contains variation of Couldn't find package error" do + let(:error_message) do + "Couldn't find package \"source-map-explorer\" on the \"npm\" registry." + end + + it "raises the corresponding error class with the correct message" do + expect { error_handler.handle_group_patterns(error, usage_error_message, { yarn_lock: yarn_lock }) } + .to raise_error(Dependabot::DependencyFileNotResolvable, + "Couldn't find package \"source-map-explorer\" on the \"npm\" registry.") + end + end + + context "when the error message contains variation of Couldn't find package error" do + let(:error_message) do + "Couldn't find package \"dl-core-js@^1.0.0\" required by \"mahso-slide-gen@0.1.0\" on the \"npm\" registry." + end + + it "raises the corresponding error class with the correct message" do + expect { error_handler.handle_group_patterns(error, usage_error_message, { yarn_lock: yarn_lock }) } + .to raise_error(Dependabot::DependencyFileNotResolvable, + "Couldn't find package \"dl-core-js@^1.0.0\" required" \ + " by \"mahso-slide-gen@0.1.0\" on the \"npm\" registry.") + end + end + context "when the error message contains YARNRC_ENV_NOT_FOUND" do let(:error_message) do "Usage Error: Environment variable not found (GITHUB_TOKEN) in /home/dependabot/dependabot-" \