Skip to content

Commit 28e8488

Browse files
authored
fix: Fallback to manual navigation when opening the browser automatically during token provisioning fails (#256)
1 parent 66da27a commit 28e8488

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/config_inference.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function inferProject(api: API, dryRun: boolean, orgName?: string) {
9696
spinner.fail(
9797
`Guessing project name '${projectName}': Creating project...`,
9898
);
99-
error(e.code);
99+
error(e);
100100
}
101101
}
102102
}

src/utils/access_token.ts

+24-19
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,22 @@ async function provision(): Promise<string> {
5959
break;
6060
}
6161
}
62-
const open = openCmd !== undefined
63-
? new Deno.Command(openCmd, {
64-
args: [url],
65-
stderr: "piped",
66-
stdout: "piped",
67-
})
68-
.spawn()
69-
: undefined;
70-
62+
let open;
63+
if (openCmd !== undefined) {
64+
try {
65+
open = new Deno.Command(openCmd, {
66+
args: [url],
67+
stderr: "piped",
68+
stdout: "piped",
69+
})
70+
.spawn();
71+
} catch (error) {
72+
wait("").start().warn(
73+
"Unexpected error while trying to open the authorization URL in your default browser. Please report it at https://github.com/denoland/deployctl/issues/new.",
74+
);
75+
wait({ text: "", indent: 3 }).start().fail(error.toString());
76+
}
77+
}
7178
if (open == undefined) {
7279
const warn =
7380
"Cannot open the authorization URL automatically. Please navigate to it manually using your usual browser";
@@ -76,17 +83,15 @@ async function provision(): Promise<string> {
7683
const warn =
7784
"Failed to open the authorization URL in your default browser. Please navigate to it manually";
7885
wait("").start().warn(warn);
79-
if (open !== undefined) {
80-
let error = new TextDecoder().decode((await open.output()).stderr);
81-
const errIndent = 2;
82-
const elipsis = "...";
83-
const maxErrLength = warn.length - errIndent;
84-
if (error.length > maxErrLength) {
85-
error = error.slice(0, maxErrLength - elipsis.length) + elipsis;
86-
}
87-
// resulting indentation is 1 less than configured
88-
wait({ text: "", indent: errIndent + 1 }).start().fail(error);
86+
let error = new TextDecoder().decode((await open.output()).stderr);
87+
const errIndent = 2;
88+
const elipsis = "...";
89+
const maxErrLength = warn.length - errIndent;
90+
if (error.length > maxErrLength) {
91+
error = error.slice(0, maxErrLength - elipsis.length) + elipsis;
8992
}
93+
// resulting indentation is 1 less than configured
94+
wait({ text: "", indent: errIndent + 1 }).start().fail(error);
9095
}
9196

9297
const spinner = wait("Waiting for authorization...").start();

0 commit comments

Comments
 (0)