Skip to content

[Bug?]: yarn config get / unset throws Usage Error when a setting isn't in the config #5479

Closed as not planned
@michaelfaith

Description

@michaelfaith

Self-service

  • I'd be willing to implement a fix

Describe the bug

Whenever you use the yarn config unset <settingName> or yarn config get <settingName> command, with a setting name that isn't present in the config, it throws a Usage Error: Couldn't find a configuration settings named <settingName>. This can be problematic when used in a CI/CD context. For example, we have reusable pipeline templates that service multiple projects. Some of those projects use the afterInstall plugin and so those config files have afterInstall settings applied. When bumping versions in our pipeline, we don't want the afterInstall scripts to run. So we have code that unsets the afterInstall setting and re-sets it at the end of the stage. Blindly unsetting that property would be ideal, but since that throws an Error, I tried using the config get command to see if that setting is present before unsetting, but even that throws an error.

It seems like the behavior for both calls should be a no-op. CLI's like git will just return an empty string if you try and get a config prop that isn't there. It doesn't error out (e.g. git config --get user.phone). Similarly, if you're trying to unset a prop that isn't there, I would expect it to just do nothing, not throw an error.

I wasn't sure if this should be considered a Bug or an Enhancement, so if it needs to be re-labled/re-titled, that's totally cool.

To reproduce

Run yarn config unset afterInstall or yarn config get afterInstall on a project that doesn't have afterInstall set.

Environment

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11500H @ 2.90GHz
  Binaries:
    Node: 16.19.0 - ~\AppData\Local\Temp\xfs-de411936\node.CMD
    Yarn: 3.5.1 - ~\AppData\Local\Temp\xfs-de411936\yarn.CMD
    npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD

Additional context

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleIssues that didn't get attentionwaiting for feedbackWill autoclose in a while unless more data are provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions