Skip to content

Make bundle config get return status 1 when the value is not set#9505

Open
willnet wants to merge 1 commit intoruby:masterfrom
willnet:bundle-config-get-return-error-status
Open

Make bundle config get return status 1 when the value is not set#9505
willnet wants to merge 1 commit intoruby:masterfrom
willnet:bundle-config-get-return-error-status

Conversation

@willnet
Copy link
Copy Markdown
Contributor

@willnet willnet commented Apr 30, 2026

Fix #3215

Change the exit status to 1 when trying to get a config key that does not exist, as shown below.

$ bundle config get foo

Settings for `foo` in order of priority. The top value will be used

You have not configured a value for `foo`

$ echo $?
1

It seems that showing “Settings for foo in order of priority. The top value will be used” when the key does not exist is not very meaningful, but for now I have left the behavior unchanged except for the exit status.

In the tests, some existing cases try to get a missing config without raise_on_error: false, so set the value in advance or add raise_on_error: false to handle them.

Fix ruby#3215

Change the exit status to 1 when trying to `get` a config key that does not exist, as shown below.

```sh
$ bundle config get foo

Settings for `foo` in order of priority. The top value will be used

You have not configured a value for `foo`

$ echo $?
1
```

It seems that showing “Settings for `foo` in order of priority. The top value will be used” when the key does not exist is not very meaningful, but for now I have left the behavior unchanged except for the exit status.

In the tests, some existing cases try to `get` a missing config without `raise_on_error: false`, so set the value in advance or add `raise_on_error: false` to handle them.
Comment on lines +91 to +110
configured = Bundler.settings.locations(name).any?

if options[:parseable]
if value = Bundler.settings[name]
Bundler.ui.info("#{name}=#{value}")
end
return
if configured
return
else
exit 1
end
end

confirm(name)
return

if configured
return
else
exit 1
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about simplifying this?

if value.nil?
  warn_unused_scope "Ignoring --#{scope} since no value to set was given"
  current_value = Bundler.settings[name]
  if options[:parseable]
    if current_value
      Bundler.ui.info("#{name}=#{current_value}")
    end
  else
    confirm(name)
  end

  if current_value
    return
  else
    exit 1
  end
end

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.

bundle config exits with successful exit status even when requested setting isn't set

3 participants