Skip to content

Commit

Permalink
Fix : Dependabot::DependabotError: [YN0001] issues (#10473)
Browse files Browse the repository at this point in the history
* Fix : Dependabot:DependabotError: [YN0001] issues
  • Loading branch information
sachin-sandhu authored Aug 21, 2024
1 parent 86ab940 commit 0edf2e5
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 0 deletions.
27 changes: 27 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
end

module Dependabot
# rubocop:disable Metrics/ModuleLength
module NpmAndYarn
NODE_VERSION_NOT_SATISFY_REGEX = /The current Node version (?<current_version>v?\d+\.\d+\.\d+) does not satisfy the required version (?<required_version>v?\d+\.\d+\.\d+)\./ # rubocop:disable Layout/LineLength

Expand Down Expand Up @@ -125,6 +126,19 @@ module NpmAndYarn
YARNRC_ENOENT = /Internal Error: ENOENT/
YARNRC_ENOENT_REGEX = /Internal Error: ENOENT: no such file or directory, stat '(?<filename>.*?)'/

YN0001_FILE_NOT_RESOLVED_CODES = T.let({
FIND_PACKAGE_LOCATION: /YN0001: UsageError: Couldn't find the (?<pkg>.*) state file/,
NO_CANDIDATE_FOUND: /YN0001: Error: (?<pkg>.*): No candidates found/,
NO_SUPPORTED_RESOLVER: /YN0001:*.*Error: (?<pkg>.*) isn't supported by any available resolver/,
WORKSPACE_NOT_FOUND: /YN0001: Error: (?<pkg>.*): Workspace not found/,
ENOENT: /YN0001:*.*Thrown Error: (?<pkg>.*) ENOENT/,
MANIFEST_NOT_FOUND: /YN0001: Error: (?<pkg>.*): Manifest not found/
}.freeze, T::Hash[String, Regexp])

YN0001_AUTH_ERROR_CODES = T.let({
AUTH_ERROR: /YN0001:*.*Fatal Error: could not read Username for '(?<url>.*)': terminal prompts disabled/
}.freeze, T::Hash[String, Regexp])

class Utils
extend T::Sig

Expand Down Expand Up @@ -165,6 +179,18 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock)
"YN0001" => {
message: "Exception error",
handler: lambda { |message, _error, _params|
YN0001_FILE_NOT_RESOLVED_CODES.each do |(_yn0001_key, yn0001_regex)|
if (msg = message.match(yn0001_regex))
return Dependabot::DependencyFileNotResolvable.new(msg)
end
end

YN0001_AUTH_ERROR_CODES.each do |(_yn0001_key, yn0001_regex)|
if (msg = message.match(yn0001_regex))
url = msg.named_captures.fetch(URL_CAPTURE)
return Dependabot::PrivateSourceAuthenticationFailure.new(url)
end
end
Dependabot::DependabotError.new(message)
}
},
Expand Down Expand Up @@ -460,4 +486,5 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock)
matchfn: T.nilable(T.proc.params(usage: String, message: String).returns(T::Boolean))
}])
end
# rubocop:enable Metrics/ModuleLength
end
184 changes: 184 additions & 0 deletions npm_and_yarn/spec/dependabot/npm_and_yarn/yarn_error_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,190 @@
end
end

context "when the error message contains YN0001 response (No candidates found)" do
let(:error_message) do
"[YN0001]: Exception error, Detail: ➤ YN0000: ┌ Resolution step
::group::Resolution step
➤ YN0001: │ Error: @mui/material@npm:>5.16.7: No candidates found
at ge (/home/dependabot/.cache/node/corepack/yarn/3.6.3/yarn.js:439:8124)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.allSettled (index 4)
at async io (/home/dependabot/.cache/node/corepack/yarn/3.6.3/yarn.js:390:10398)
::endgroup::
➤ YN0001: Error: @mui/material@npm:>5.16.7: No candidates found
at ge (/home/dependabot/.cache/node/corepack/yarn/3.6.3/yarn.js:439:8124)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.allSettled (index 4)
at async io (/home/dependabot/.cache/node/corepack/yarn/3.6.3/yarn.js:390:10398)
➤ YN0000: └ Completed in 0s 305ms
➤ YN0000: Failed with errors in 0s 313ms"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"YN0001: Error: @mui/material@npm:>5.16.7: No candidates found")
end
end

context "when the error message contains YN0001 response (findPackageLocation)" do
let(:error_message) do
"[YN0001]: Exception error, Detail: ➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 0s 709ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0073: │ Skipped due to mode=update-lockfile
➤ YN0000: └ Completed
➤ YN0001: UsageError: Couldn't find the node_modules state file - running an install might help" \
" (findPackageLocation)
at nb.findPackageLocation (/home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:695:21634)
at async /home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:424:1591
at async Promise.all (index 2)
at async NB (/home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:424:1319)
at async wV (/home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:424:1934)
at async DRe (/home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:423:3297)
at async /home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:423:2583
at async Zt.mktempPromise (/home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:314:69069)
at async Object.TB (/home/dependabot/.cache/node/corepack/yarn/3.8.2/yarn.js:423:2523)
at async afterAllInstalled (/home/dependabot/dependabot-updater/repo/.yarn/plugins/:" \
"@yarnpkg/plugin-postinstall-dev.cjs:6:947)
➤ YN0000: Failed with errors in 1s 78ms"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"YN0001: UsageError: Couldn't find the node_modules state file")
end
end

context "when the error message contains YN0001 response (no available resolver)" do
let(:error_message) do
"[YN0001]: Exception error, Detail: ➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: @babel/plugin-proposal-decorators@^7.10.05 isn't supported by any available resolver
at Dd.getResolverByDescriptor (/home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:141:1698)
at Dd.getResolutionDependencies (/home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:141:1177)
at aC.getResolutionDependencies (/home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:203:642)
at Dd.getResolutionDependencies (/home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:141:1206)
at Fe (/home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:210:8191)
at /home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:210:8976
at async Promise.allSettled (index 1)
at async Uc (/home/dependabot/.cache/node/corepack/yarn/4.1.1/yarn.js:140:53244)
➤ YN0000: └ Completed in 0s 763ms
➤ YN0000: · Failed with errors in 0s 780ms"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"YN0001: │ Error: @babel/plugin-proposal-decorators@^7.10.05 isn't supported by any" \
" available resolver")
end
end

context "when the error message contains YN0001 response (Workspace not found)" do
let(:error_message) do
" at /home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:210:8334
at Yy (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:140:53922)
at xe (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:210:8314)
at async Promise.allSettled (index 6)
at async Uc (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:140:53250)
::endgroup::
➤ YN0001: Error: @reelbi/revideo-components@workspace:^: Workspace not found " \
"(@reelbi/revideo-components@workspace:^)
at St.getWorkspaceByDescriptor" \
" (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:210:3520)
at o1.getCandidates (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:140:115282)
at Bd.getCandidates (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:141:1311)
at Bd.getCandidates (/home/dependabot/dependabot-updater/repo/project/.yarn/releases/yarn-4.0.1.cjs:141:1311)"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"YN0001: Error: @reelbi/revideo-components@workspace:^: Workspace not found")
end
end

context "when the error message contains YN0001 response (ENOENT)" do
let(:error_message) do
"➤ YN0001: @sesamecare/eslint-config@npm:1.1.9::" \
"__archiveUrl=https%3A%2F%2Fus-central1-npm.pkg.dev%2Fsesame-care-dev%2Fnpm" \
"-packages%2F%40sesamecare%2Feslint-config%2F-%2F%40sesamecare%2Feslint-config-1.1.9.tgz: " \
"Process gcloud failed to spawn
➤ YN0001: Thrown Error: spawn gcloud ENOENT
➤ YN0001: @sesamecare/svg-icons@npm:2.8.0::__archiveUrl=https%3A%2F%2Fus-central1" \
"-npm.pkg.dev%2Fsesame-care-dev%2Fnpm-packages%2F%40sesamecare%2Fsvg-icons%2F-%2F%40sesamecare%2Fsvg" \
"-icons-2.8.0.tgz: Process gcloud failed to spawn
➤ YN0001: Thrown Error: spawn gcloud ENOENT
➤ YN0000: └ Completed in 0s 741ms
➤ YN0000: Failed with errors in 1s 370ms"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"YN0001: Thrown Error: spawn gcloud ENOENT")
end
end

context "when the error message contains YN0001 response (Manifest not found)" do
let(:error_message) do
" at async Yy (/home/dependabot/dependabot-updater/repo/.yarn/releases/yarn-4.3.1.cjs:140:53795)
at async Z (/home/dependabot/dependabot-updater/repo/.yarn/releases/yarn-4.3.1.cjs:210:7231)
at async Promise.allSettled (index 24)
::endgroup::
➤ YN0001: Error: dior-ds@portal:../../submodules/crp-design-system::locator=%40onedior%2Fcdc-header" \
"-v3%40workspace%3Apackages%2Flib-cdc-header-v3: Manifest not found
at cE.find (/home/dependabot/dependabot-updater/repo/.yarn/releases/yarn-4.3.1.cjs:140:120099)
at async /home/dependabot/dependabot-updater/repo/.yarn/releases/yarn-4.3.1.cjs:571:3627
at async Object.xZe (/home/dependabot/dependabot-updater/repo/.yarn/releases/yarn-4.3.1.cjs:140:53711)"
end

it "raises a DependencyFileNotResolvable error with the correct message" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::DependencyFileNotResolvable,
"YN0001: Error: dior-ds@portal:../../submodules/crp-design-system::" \
"locator=%40onedior%2Fcdc-header-v3%40workspace%3Apackages%2Flib-cdc-header-v3" \
": Manifest not found")
end
end

context "when the error message contains YN0001 response (could not read Username)" do
let(:error_message) do
"➤ YN0000: ┌ Resolution step
➤ YN0013: │ rescript-unicons@https://github.com/makerinc/[FILTERED_REPO]" \
"#commit=5df21175b54ddab488905424152f440ae8454506 can't be found in the cache and :" \
"will be fetched from GitHub
➤ YN0001: │ @makerinc/makerbelt@https://github.com/makerinc/" \
"[FILTERED_REPO]#d4b99ffe39559727e2d4e32648beb1f9bea7564d: Failed listing refs
➤ YN0001: │ Repository URL: https://github.com/makerinc/[FILTERED_REPO]
➤ YN0001: │ Fatal Error: could not read Username for 'https://npk.src.com/makerinc/':" \
" terminal prompts disabled
➤ YN0001: │ Exit Code: 128
➤ YN0000: └ Completed in 2s 819ms
➤ YN0000: Failed with errors in 2s 823ms
"
end

it "raises a GitDependenciesNotReachable error with the repo URL" do
expect do
error_handler.handle_yarn_error(error, { yarn_lock: yarn_lock })
end.to raise_error(Dependabot::PrivateSourceAuthenticationFailure,
"The following source could not be reached as it " \
"requires authentication (and any provided details were invalid or lacked " \
"the required permissions): https://npk.src.com/makerinc/")
end
end

context "when the error message contains YN0082" do
let(:error_message) do
"➤ YN0000: · Yarn 4.3.1\n" \
Expand Down

0 comments on commit 0edf2e5

Please sign in to comment.