Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: Throwing Error in syncEnvVars does not stop deployment #1641

Open
DaniloTrotta opened this issue Jan 27, 2025 · 1 comment
Open

bug: Throwing Error in syncEnvVars does not stop deployment #1641

DaniloTrotta opened this issue Jan 27, 2025 · 1 comment

Comments

@DaniloTrotta
Copy link

Provide environment information

System:
OS: macOS 14.6.1
CPU: (8) arm64 Apple M1
Memory: 210.30 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.1.0 - ~/.nvm/versions/node/v20.1.0/bin/node
Yarn: 1.18.0 - /usr/local/bin/yarn
npm: 9.6.4 - ~/.nvm/versions/node/v20.1.0/bin/npm
pnpm: 9.10.0 - ~/.nvm/versions/node/v20.1.0/bin/pnpm
bun: 1.0.1 - ~/.bun/bin/bun

Describe the bug

I've encountered an unexpected behavior with error handling in the syncEnvVars callback:

Current behavior:
We throw an error when required env vars are missing
The error appears as a warning message
Deployment continues despite the error

Expected behavior:
Deployment should stop when the error is thrown

Reproduction repo

https://trigger.dev/docs/deploy-environment-variables#the-syncenvvars-callback-return-type

To reproduce

Just throwing any kind of error in the syncEnvVars callback

Additional information

Image

@whchi
Copy link

whchi commented Feb 18, 2025

I encountered the same problem. After tracing the code, I found that in the callSyncEnvVarsFn function, any errors are caught and the function simply returns without doing anything.
Here's the relevant code from syncEnvVars.ts line 147:

    try {
      result = await syncEnvVarsFn({
        projectRef: context.config.project,
        environment,
        env,
      });
    } catch (error) {
      context.logger.warn("Error calling syncEnvVars function", error);
    }

    if (!result) {
      return;
    }

While env sync failures shouldn't always block deployments, it might be worth considering cases where certain environment variables are critical for the system to function properly.

One possible approach could be to create a specific error type called SyncEnvVarError. This error would be used specifically within the syncEnvVars function, and when thrown, it would stop the deployment process.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants