Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/envvars-update-name-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---

Fix `envvars.update()` throwing `ReferenceError: name is not defined` when called outside a task run (for example from a deploy script).
6 changes: 5 additions & 1 deletion packages/trigger-sdk/src/v3/envvars.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,17 @@ export function update(
throw new Error("projectRef is required");
}

if (typeof nameOrRequestOptions !== "string") {
throw new Error("name is required");
}

if (!params) {
throw new Error("params is required");
}

$projectRef = projectRefOrName;
$slug = slugOrParams;
$name = name!;
$name = nameOrRequestOptions;
$params = params;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/trigger-sdk/src/v3/triggerClient.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe("TriggerClient surface — type-level guarantees", () => {
// Zero-arg form (uses task context — still typeable at the call site)
expectTypeOf(client.envvars.list).toBeCallableWith();
});

it("preserves envvars.update overloads (out of task context form AND in-task form)", () => {
// Four-arg form (out-of-task: projectRef, slug, name, params)
expectTypeOf(client.envvars.update).toBeCallableWith("proj_1234", "dev", "MY_VAR", {
value: "secret",
});
// Two-arg form (in-task: name, params)
expectTypeOf(client.envvars.update).toBeCallableWith("MY_VAR", { value: "secret" });
});
});

describe("TriggerClient surface — curated subsets", () => {
Expand Down