Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

list_pages still answers empty when the page-type count behind its note fails

garrytan5bbcd2d8933f
diff --git a/src/core/ops/list-pages-pagination.ts b/src/core/ops/list-pages-pagination.ts
index 104636039a..00918932d4 100644
--- a/src/core/ops/list-pages-pagination.ts
+++ b/src/core/ops/list-pages-pagination.ts
@@ -85,9 +85,9 @@ export function listingTruncatedNotice(pagination: ListPagesPagination, params:
/** How many page types the unused-type notice names, most pages first. */
export const UNUSED_TYPE_NAMED = 12;
-/** The notice for an empty list_pages whose `type` no visible page has; null when some visible page has it. */
-export function unusedTypeNotice(type: string, visible: Array<{ type: string; pages: number }>): Notice | null {
- if (visible.some(t => t.type === type)) return null;
+/** The notice for an empty list_pages whose `type` no visible page has; null when some visible page has it or the type count failed (null). */
+export function unusedTypeNotice(type: string, visible: Array<{ type: string; pages: number }> | null): Notice | null {
+ if (!visible || visible.some(t => t.type === type)) return null;
const named = visible.slice(0, UNUSED_TYPE_NAMED).map(t => `${t.type} (${t.pages})`).join(', ');
const more = visible.length > UNUSED_TYPE_NAMED ? `, and ${visible.length - UNUSED_TYPE_NAMED} more` : '';
return {
diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.ts
index 03a6cc88bc..15f738b45c 100644
--- a/src/core/ops/pages.ts
+++ b/src/core/ops/pages.ts
@@ -667,7 +667,7 @@ const list_pages: Operation = {
const truncatedNotice = isLocal ? null : listingTruncatedNotice(pagination, p);
if (truncatedNotice) ctx.emitNotice?.(truncatedNotice);
if (pages.length === 0 && typeof p.type === 'string' && p.type) {
- const notice = unusedTypeNotice(p.type, await (await import('./stats-by.ts')).visiblePageTypes(ctx, scope));
+ const notice = unusedTypeNotice(p.type, await (await import('./stats-by.ts')).visiblePageTypes(ctx, scope).catch(() => null));
if (notice) ctx.emitNotice?.(notice);
}
return pages.map(pg => ({
diff --git a/test/list-pages-empty-type-notice-gbra449.test.ts b/test/list-pages-empty-type-notice-gbra449.test.ts
index bbe0aed245..096460cd1a 100644
--- a/test/list-pages-empty-type-notice-gbra449.test.ts
+++ b/test/list-pages-empty-type-notice-gbra449.test.ts
@@ -106,6 +106,20 @@ for (const backend of testBackends()) {
}
});
+ test('the notice is best effort: a failed type count still answers the bare empty array', async () => {
+ const countPagesBy = engine.countPagesBy.bind(engine);
+ engine.countPagesBy = async () => { throw new Error('canceling statement due to statement timeout'); };
+ try {
+ for (const opts of [local, remote]) {
+ const r = await call({ type: 'account' }, opts);
+ expect(r.json).toEqual([]);
+ expect(r.empty).toBe('');
+ }
+ } finally {
+ engine.countPagesBy = countPagesBy;
+ }
+ });
+
test('local: a private page type is listed; a soft-deleted page type gets the notice without naming itself', async () => {
expect((await call({ type: 'memo-private' })).json.map((row: { slug: string }) => row.slug)).toEqual(['memos/private']);
const gone = await call({ type: 'memo-deleted' });