Skip to content
Merged
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
27 changes: 15 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ async function main() {
.description("The San Francisco Compute command line tool.")
.version(pkg.version);

// Hydrate `account_id` before registering commands so feature-flag-gated
// surfaces (e.g. `--enable-infiniband` on `sf nodes create`) resolve
// correctly on the very first CLI invocation after login, rather than only
// appearing after the cache has been seeded by a previous run.
const config = await loadConfig();
let exchangeAccountId = config.account_id;
if (!exchangeAccountId) {
const client = await apiClient(config.auth_token);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[🟡 Medium] [🔵 Bug]

The new pre-registration account hydration runs an unguarded network call before any command is parsed, so transient network/DNS failures can throw and terminate the process even for commands like help/version. ts // src/index.ts if (!exchangeAccountId) { const client = await apiClient(config.auth_token); const { data } = await client.GET("/v1/account/me", {}); if (data?.id) { This matters because command surfaces now depend on startup network reliability instead of failing open when feature-flag resolution is unavailable. Wrap this hydration block in try/catch (or otherwise treat failures as non-fatal) so CLI startup proceeds when account lookup cannot be completed.

const { data } = await client.GET("/v1/account/me", {});
if (data?.id) {
exchangeAccountId = data.id;
await saveConfig({ ...config, account_id: data.id });
}
}

// commands
registerLogin(program);
registerContracts(program);
Expand Down Expand Up @@ -84,18 +99,6 @@ async function main() {
process.exit(0);
});

const config = await loadConfig();
let exchangeAccountId = config.account_id;

if (!exchangeAccountId) {
const client = await apiClient(config.auth_token);
const { data } = await client.GET("/v1/account/me", {});
if (data?.id) {
exchangeAccountId = data.id;
saveConfig({ ...config, account_id: data.id });
}
}

program.exitOverride((error) => {
let isError = true;

Expand Down
Loading
Loading