Skip to content

Commit 782d4e8

Browse files
committed
fix(cli): add abort controller to notification fetch for better error handling
1 parent b79c121 commit 782d4e8

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/cli/src/actions/action-utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,11 @@ export function startNotificationFetch() {
236236
let fetchComplete = false;
237237

238238
const start = Date.now();
239+
const controller = new AbortController();
239240

240241
fetch(CLI_CONFIG_ENDPOINT, {
241242
headers: { accept: 'application/json' },
243+
signal: controller.signal,
242244
})
243245
.then(async (res) => {
244246
if (!res.ok) return;
@@ -263,7 +265,13 @@ export function startNotificationFetch() {
263265
await new Promise((resolve) => setTimeout(resolve, FETCH_CLI_MAX_TIME - elapsed));
264266
}
265267

266-
if (!fetchComplete || !fetchedData) return;
268+
if (!fetchComplete) {
269+
controller.abort();
270+
return;
271+
}
272+
273+
if (!fetchedData) return;
274+
267275
const activeItems = fetchedData.notifications.filter((item) => item.active);
268276
// show a random active item
269277
if (activeItems.length > 0) {

packages/cli/src/actions/generate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export async function run(options: Options) {
3838
console.warn(colors.yellow(`Failed to check for mismatched ZenStack packages: ${err}`));
3939
}
4040

41-
const maybeShowNotification = !options.offline && !options.silent ? startNotificationFetch() : undefined;
41+
const maybeShowNotification =
42+
!options.offline && !options.silent && !options.watch ? startNotificationFetch() : undefined;
4243

4344
const model = await pureGenerate(options, false);
4445

0 commit comments

Comments
 (0)