Coder Social home page Coder Social logo

Comments (6)

bombillazo avatar bombillazo commented on May 27, 2024 1

We've programmed some commands for that, but its not ideal and introduces more room for errors and intermediate states if something fails. A simple update flag would be the best way to handle it for our case.

from vercel.

hussamkhatib avatar hussamkhatib commented on May 27, 2024

While not ideal, you could remove the env variable vercel env rm and then add the new value.

from vercel.

mountainash avatar mountainash commented on May 27, 2024

I also have the same problem... it would be great is there was a --yes argument (that is also used on env pull and env rm to skip the confirmation/warning that the variable already exists.

from vercel.

mountainash avatar mountainash commented on May 27, 2024

I started looking into raising a PR to add this functionality and found that the Vercel API endpoint for create does allow for overriding if the KEY already exists with an upsert param.

There is also (for interest) another endpoint for "editing" an existing env var when it exists, but you need to know it's ID, not the envvar name/key (so you need to do a map first.

So it shouldn't be too much extra to change this in Vercel CLI.

from vercel.

mountainash avatar mountainash commented on May 27, 2024

What's interesting/strange/confusing is that when you attempt to vercel env add with an existing key, the CLI error is:

Error: Another Environment Variable with the same Name and Environment exists in your project. Remove it or choose a different Name or Environment.

Yet, I can't find this error message in the CLI codebase (this project), I thought maybe the API is returning this error, yet trying to create a new envar Key that already exists returns the following error from the API (https://api.vercel.com/v10/projects/${projectID}/env):

{
  "error": {
    "code": "ENV_CONFLICT",
    "message": "A variable with the name `API_URL` and target `preview` already exists",
    "key": "key",
    "envVarKey": "API_URL"
  },
  "failed": [
    {
      "error": {
        "code": "ENV_CONFLICT",
        "message": "A variable with the name `API_URL` and target `preview` already exists",
        "key": "key",
        "envVarKey": "API_URL"
      }
    }
  ]
}

I'll keep digging to see where the CLI's error is coming from (could be using an older endpoint)...

Update

Endpoint v9 is returning the error below when trying to set an existing env Key. v9 also doesn't allow the "upsert" para... so CLI will need updating to use v10 of this endpoint.

{
  "error": {
    "code": "ENV_ALREADY_EXISTS",
    "message": "Another Environment Variable with the same Name and Environment exists in your project. Remove it or choose a different Name or Environment.",
    "key": "API_URL",
    "configurationId": null,
    "target": [
      "preview"
    ]
  }
}

Update 2

CLI is using v8:
const url = /v8/projects/${projectId}/env;

from vercel.

bombillazo avatar bombillazo commented on May 27, 2024

Awesome work!

from vercel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.