Skip to content

Commit 6c3a0e4

Browse files
committed
non-TTY check for required variables:
Added a check in non-TTY environments for `account_id`, `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`. If `account_id` exists in `wrangler.toml` then `CLOUDFLARE_ACCOUNT_ID` is not needed in non-TTY scope. The `CLOUDFLARE_API_TOKEN` is necessary in non-TTY scope and will always error if missing. resolves #827
1 parent 370200f commit 6c3a0e4

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

packages/wrangler/src/__tests__/publish.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ describe("publish", () => {
233233
await expect(runWrangler("publish index.js")).rejects.toThrowError();
234234

235235
expect(std.err).toMatchInlineSnapshot(`
236-
"X [ERROR] Missing 'CLOUDFLARE_API_TOKEN' from non-TTY environment, please see docs for more info: TBD
237-
238-
239-
X [ERROR] Did not login, quitting...
236+
"X [ERROR] Missing 'CLOUDFLARE_API_TOKEN' from non-TTY environment, please see docs for more info
240237
241238
"
242239
`);

packages/wrangler/src/__tests__/whoami.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import { writeAuthConfigFile } from "../user";
44
import { getUserInfo, WhoAmI } from "../whoami";
55
import { setMockResponse } from "./helpers/mock-cfetch";
66
import { mockConsoleMethods } from "./helpers/mock-console";
7+
import { useMockIsTTY } from "./helpers/mock-istty";
78
import { runInTempDir } from "./helpers/run-in-tmp";
89
import type { UserInfo } from "../whoami";
910

1011
describe("getUserInfo()", () => {
1112
runInTempDir({ homedir: "./home" });
1213
const std = mockConsoleMethods();
14+
const { setIsTTY } = useMockIsTTY();
15+
16+
beforeEach(() => {
17+
setIsTTY(true);
18+
});
1319

1420
it("should return undefined if there is no config file", async () => {
1521
const userInfo = await getUserInfo();

packages/wrangler/src/user.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ export function getAPIToken(): string | undefined {
418418
!localAPIToken &&
419419
!LocalState.accessToken?.value
420420
) {
421-
logger.error(
422-
"Missing 'CLOUDFLARE_API_TOKEN' from non-TTY environment, please see docs for more info: TBD"
421+
throw new Error(
422+
"Missing 'CLOUDFLARE_API_TOKEN' from non-TTY environment, please see docs for more info"
423423
);
424-
425-
return;
426424
}
427425

428426
return localAPIToken ?? LocalState.accessToken?.value;

0 commit comments

Comments
 (0)