跳到正文
cccskills
免费在 GitHub 公开

hono-subapp-undefined-response-1101

Fix Cloudflare Workers Error 1101 "Worker threw exception" caused by Hono sub-app route handlers returning undefined instead of a Response. Use when: (1) Error 1101 on a specific hostname but not others sharing the same worker, (2) "the Promise did not resolve to 'Response'" in wrangler dev logs, (3) Hono sub-app route handler uses bare `return` to skip handling for non-matching hostnames or conditions. The fix is to add `next` parameter and call `return next()` instead of bare `return` in route handlers that conditionally skip.

中文简介正在准备中。当前显示原文说明。

集成工具Cloudflare
查看安装方法

包含的文件(1)

  • SKILL.md4.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Hono Sub-App Route Handler Returns Undefined → CF Error 1101

Problem

A Cloudflare Worker using Hono with sub-apps crashes with Error 1101 ("Worker threw exception") when a route handler in a sub-app returns undefined instead of a Response. This commonly happens when route handlers have hostname guards that use bare return to skip processing, intending to let other routes handle the request.

Context / Trigger Conditions

  • Cloudflare Workers dashboard or browser shows Error 1101: Worker threw exception
  • wrangler dev logs show: "Incorrect type for Promise: the Promise did not resolve to 'Response'"
  • Multiple hostnames route to the same worker (e.g., names.divine.video and names.admin.divine.video)
  • Hono sub-app has route handlers with conditional hostname checks that use bare return
  • The sub-app has middleware that calls next() for non-matching hostnames, but the route handlers duplicate the check and return undefined

Root Cause

In Hono, route handlers (.get(), .post(), etc.) MUST return a Response. Only middleware (registered via .use()) can call next() to pass control downstream.

However, if a route handler includes next in its parameter list (async (c, next) => {}), Hono treats it as middleware-like, allowing return next() to pass control to the next matching handler.

A bare return (which returns undefined) from a route handler causes the Cloudflare Workers runtime to throw because it expects a Response object.

Solution

Bad — returns undefined, crashes the worker:

app.get('/', async (c) => {
  if (!ALLOWED_HOSTNAMES.includes(hostname)) {
    return // undefined! → Error 1101
  }
  return c.html(page())
})

Good — accepts next parameter and calls it to pass control:

app.get('/', async (c, next) => {
  if (!ALLOWED_HOSTNAMES.includes(hostname)) {
    return next() // passes to next handler in chain
  }
  return c.html(page())
})

Key insight: Adding next to the handler signature changes Hono's treatment of the handler, allowing it to delegate to downstream routes.

Verification

  1. Run wrangler dev and curl with the non-matching hostname:
    curl -s -o /dev/null -w "%{http_code}" http://localhost:8787/ -H "Host: other.example.com"
    
  2. Should return a valid HTTP status (200, 404, etc.) instead of 500
  3. No "did not resolve to Response" errors in the terminal

Example

A worker serves both names.divine.video (public UI) and names.admin.divine.video (admin SPA). The public routes sub-app has a landing page handler that only responds for names.divine.video. When names.admin.divine.video hits this handler, it should pass through to the catch-all admin SPA handler. Using bare return crashes the worker; using return next() (with next in params) properly delegates.

Notes

  • This only applies to Hono route handlers, not middleware (.use() handlers always have next)
  • The error is invisible in Cloudflare's dashboard — you only see generic "Error 1101"
  • wrangler dev gives the real error: "the Promise did not resolve to 'Response'"
  • If your sub-app middleware already guards routes, you may not need hostname checks in individual handlers at all — but if you do, use the next pattern
  • This pattern is common in multi-tenant workers where one worker handles multiple hostnames

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y". Use when: (1) ExternalSecret shows OutOfSync in ArgoCD but won't sync, (2) ArgoCD application status shows "namespace X is not permitted in project 'infrastructure'", (3) ExternalSecret targets a namespace managed by a different ArgoCD project, (4) Using apps-of-apps pattern with separate infrastructure and application projects.

中文简介正在准备中。当前显示原文说明。

divinevideo/divine-mobile2652026年10月22日 更新

Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language. After selection, generates AI image prompts and visual briefs section-by-section. Use when the user shares content and needs visual direction, image sourcing, or creative direction for any material.

中文简介正在准备中。当前显示原文说明。

divinevideo/divine-mobile2652026年10月22日 更新

Fix "Null check operator used on a null value" errors when an object is set to null during an async await. Use when: (1) Object reference is nullified while awaiting, (2) Code accesses object with ! after await returns, (3) Cancel/dispose operations run concurrently with async operations on same object. Solution: capture local reference before await.

中文简介正在准备中。当前显示原文说明。

divinevideo/divine-mobile2652026年10月22日 更新

Add custom metadata headers (x-amz-meta-*) to AWS v4 signed requests for GCS S3-compatible API. Use when: (1) Adding custom metadata to GCS uploads via S3 API, (2) Getting signature mismatch errors after adding new headers, (3) x-amz-meta-* headers being ignored or causing 403 errors. Custom headers MUST be included in canonical headers and signed headers list.

中文简介正在准备中。当前显示原文说明。

divinevideo/divine-mobile2652026年10月22日 更新

Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings. Use when: (1) Password authentication fails with correct password, (2) Secret created with `<<< "value"` syntax, (3) Error like "password authentication failed" or "invalid token" despite correct value. Bash here-strings (`<<<`) add a trailing newline that corrupts secrets.

中文简介正在准备中。当前显示原文说明。

divinevideo/divine-mobile2652026年10月22日 更新

Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp). Use when: (1) Media moderation, transcoding, or analysis silently skips files from Blossom or content-addressed storage servers, (2) URL extraction from Nostr event tags (imeta, r tags) drops URLs without recognized extensions, (3) CDN fallback URLs append .mp4 but the actual server uses extensionless content-addressed paths like /{sha256}. Common in Nostr video events (kind 34236) where different clients use different URL formats.

中文简介正在准备中。当前显示原文说明。

divinevideo/divine-mobile2652026年10月22日 更新

查看 divinevideo 的全部技能

报告此技能的问题