lingo.dev icon indicating copy to clipboard operation
lingo.dev copied to clipboard

The Build Mode Environment Variable Needs Validation

Open NiranjanKumar001 opened this issue 11 months ago • 11 comments

What's happening?

Right now, when someone sets the LINGO_BUILD_MODE environment variable to control how translations work during a build, there’s no validation of the value. That means even if they accidentally type something incorrect like LINGO_BUILD_MODE=production or LINGO_BUILD_MODE=dev (or any random typo)—the system still accepts it. As a result, the build can behave in unexpected or confusing ways.

In reality, only two values should be allowed: "translate" and "cache-only". However, the code doesn’t currently check for this, so invalid values slip through without any warning.

Exact Reproduction Steps

1.LINGO_BUILD_MODE=invalid pnpm build
or 2.LINGO_BUILD_MODE=production pnpm build or 3.LINGO_BUILD_MODE=dev pnpm build

Expected

Error: Invalid LINGO_BUILD_MODE: "invalid". Must be "translate" or "cache-only"

Actual

Right now, if you set LINGO_BUILD_MODE to an invalid value (for example, LINGO_BUILD_MODE=invalid), the build system doesn’t complain at all. It doesn’t warn you or say, “Hey, that’s not a valid option.”

Instead, this is what happens:

The build starts normally, so everything looks fine at first

It even prints the invalid value, like Build mode: invalid (as shown in the screenshot)

The build keeps running for a while

Eventually, it crashes with a confusing error message that doesn’t clearly explain the real problem

So if you accidentally type something like LINGO_BUILD_MODE=prod instead of cache-only, you won’t realize your mistake right away. You’ll sit there thinking the build is working, until it suddenly fails with errors about missing API keys or translation issues. Only then do you have to go back and figure out what went wrong.

This is especially frustrating because the actual fix is trivial—just correcting a typo. But instead of pointing you to the real issue, the error messages send you down a long debugging path for something that should have been caught immediately.

Screenshots/Videos

Image

NiranjanKumar001 avatar Dec 24 '25 22:12 NiranjanKumar001

I’d really appreciate it if this could be assigned as early as possible.

NiranjanKumar001 avatar Dec 24 '25 22:12 NiranjanKumar001

Can i work on this issue?

paras-verma7454 avatar Dec 26 '25 21:12 paras-verma7454

unless assigned i think working would be of no worth

NiranjanKumar001 avatar Dec 27 '25 00:12 NiranjanKumar001

Well it's was just a simple if else so I created a PR ASAP after seeing your issue then I read docs about PR. so I closed the PR and now waiting for assignment 😅

paras-verma7454 avatar Dec 27 '25 05:12 paras-verma7454

@paras-verma7454 it's great to see that you want to contribute but let's ask @NiranjanKumar001 if they want to raise a PR since it is their issue.

Do you want to take this up @NiranjanKumar001 ?

sumitsaurabh927 avatar Dec 28 '25 05:12 sumitsaurabh927

Okay, no problem. Could you please check my closed PR and let me know if I did it correctly? I’m new to open source, and I only added a simple if check. @sumitsaurabh927

PR: https://github.com/lingodotdev/lingo.dev/pull/1714

paras-verma7454 avatar Dec 28 '25 05:12 paras-verma7454

Yes sir, I’d be happy to take this up and work on it. Please assign it to me. @sumitsaurabh927

NiranjanKumar001 avatar Dec 28 '25 07:12 NiranjanKumar001

assigned to you @NiranjanKumar001 . before implementing please propose tech design in several options - let's make sure your architecture is compatible with the rest of the system

maxprilutskiy avatar Jan 20 '26 20:01 maxprilutskiy

@NiranjanKumar001, are you still planning to work on this one?

vrcprl avatar Feb 02 '26 08:02 vrcprl

@NiranjanKumar001, are you still planning to work on this one?

Yup will soon provide proper plan and will raise PR.

NiranjanKumar001 avatar Feb 02 '26 08:02 NiranjanKumar001

@maxprilutskiy @vrcprl

what m gonna do?

Create a dedicated validation module that:

  • Defines the only two allowed values — translate and cache-only — in a single place
  • Validates the environment variable as soon as the build starts
  • Throws a clear, helpful error immediately if an invalid value is used
  • Explicitly shows which values are allowed

Error message example: "Invalid LINGO_BUILD_MODE: 'production'. Must be one of: 'translate', 'cache-only'."

This way, developers instantly understand what went wrong and how to fix it, instead of running into confusing errors later in the build process.

Why this works:

  • Early validation – Fails fast before any build logic runs
  • Clear errors – Clearly explains what’s wrong and what’s allowed
  • Type-safe – TypeScript helps prevent mistakes
  • Single source of truth – Valid modes are defined in one place
  • Easy to maintain – Adding new modes later is straightforward

Testing plan:

  • Invalid values like production, dev → should show a clear error
  • Valid values like translate, cache-only → should work normally
  • Environment variable overriding config → should follow the correct priority

please reply if any changes required ,i will revamp the design if ok then i would raise after approval.

NiranjanKumar001 avatar Feb 05 '26 15:02 NiranjanKumar001