From d6616a5f735dbea338d0ef2596ba421ce029f233 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Tue, 23 Mar 2021 16:25:18 +0000 Subject: [PATCH] Avoid subtle runtime failures by raising if bundler is improperly invoked --- bundler/helpers/v1/run.rb | 14 ++++++++++++++ bundler/helpers/v2/run.rb | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/bundler/helpers/v1/run.rb b/bundler/helpers/v1/run.rb index 585ff96b8d1..6878bfc7231 100644 --- a/bundler/helpers/v1/run.rb +++ b/bundler/helpers/v1/run.rb @@ -11,11 +11,25 @@ require "functions" +MAX_BUNDLER_VERSION="2.0.0" + +def validate_bundler_version! + return true if correct_bundler_version? + + raise StandardError, "Called with Bundler '#{Bundler::VERSION}', expected < '#{MAX_BUNDLER_VERSION}'" +end + +def correct_bundler_version? + Gem::Version.new(Bundler::VERSION) < Gem::Version.new(MAX_BUNDLER_VERSION) +end + def output(obj) print JSON.dump(obj) end begin + validate_bundler_version! + request = JSON.parse($stdin.read) function = request["function"] diff --git a/bundler/helpers/v2/run.rb b/bundler/helpers/v2/run.rb index c4a6dad8fc2..1de28452f52 100644 --- a/bundler/helpers/v2/run.rb +++ b/bundler/helpers/v2/run.rb @@ -11,11 +11,25 @@ require "functions" +MIN_BUNDLER_VERSION = "2.0.0" + +def validate_bundler_version! + return true if correct_bundler_version? + + raise StandardError, "Called with Bundler '#{Bundler::VERSION}', expected >= '#{MIN_BUNDLER_VERSION}'" +end + +def correct_bundler_version? + Gem::Version.new(Bundler::VERSION) >= Gem::Version.new(MIN_BUNDLER_VERSION) +end + def output(obj) print JSON.dump(obj) end begin + validate_bundler_version! + request = JSON.parse($stdin.read) function = request["function"]