fix(sdk): resolve ReferenceError in envvars.update outside task context#4291
Conversation
The non-task overload of envvars.update assigned $name from an undeclared `name` identifier instead of `nameOrRequestOptions`, so management-API calls threw ReferenceError in Node. Validate and use the real parameter. Closes triggerdotdev#4264
🦋 Changeset detectedLatest commit: 9a71ef6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 26 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hi @ANSHSINGH050404, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughUpdated ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🔍 In-task 4-arg update form sends slug as projectRef
The PR fixes the out-of-task branch (envvars.ts:335-346), which is now correct. However the in-task branch of the same update function has a related pre-existing bug that this PR does not address. When update(projectRef, slug, name, params) (the 4-arg overload) is called from inside a task, taskContext.ctx is truthy and slugOrParams is a string, so execution enters envvars.ts:307-319. There $projectRef = slugOrParams assigns the slug argument to the project ref (envvars.ts:308), and $slug = slugOrParams ?? taskContext.ctx.environment.slug also resolves to the slug — so the real projectRefOrName (the actual project ref) is dropped entirely and the wrong value is sent to updateEnvVar. Compare with create/upload (envvars.ts:147-152) which correctly use $projectRef = projectRefOrParams and derive $slug from slugOrRequestOptions. Additionally the $name fallback at envvars.ts:310-313 falls back to environment.slug rather than throwing/using the name, which is also incorrect. This branch is reachable because the type overloads permit the 4-arg form regardless of task context. It is outside the changed diff hunk so it could not be reported as a bug, but a reviewer should decide whether to fix it in the same PR since it is in the exact function being patched.
(Refers to lines 307-324)
Was this helpful? React with 👍 or 👎 to provide feedback.
Closes #4264
✅ Checklist
Summary
envvars.update(projectRef, slug, name, params)crashed outside a task run with:In the non-task branch the third parameter is named
nameOrRequestOptions, but the code assigned$name = name!. That identifier is not a parameter (and is only a browser global), so Node throws.create/del/retrieve/listwere already fine on the same path.Fix
typeof nameOrRequestOptions === string(clear error if missing)$name = nameOrRequestOptions@trigger.dev/sdkTesting
pnpm run build --filter @trigger.dev/sdk pnpm --filter @trigger.dev/sdk exec vitest run src/v3/triggerClient.types.test.ts --runenvvars.updateoverload cases)dist/commonjs/v3/envvars.jsusesnameOrRequestOptionsfor$nameChangelog
Fix
envvars.update()throwingReferenceError: name is not definedwhen called outside a task run (for example from a deploy script).Note for maintainers
Vouch request: #4290