bug: Throwing Error in syncEnvVars does not stop deployment
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
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.