Skip to content

Improve invalid route return guidance#150

Open
zergzorg wants to merge 5 commits into
tscircuit:mainfrom
zergzorg:codex/invalid-empty-response-guidance-30
Open

Improve invalid route return guidance#150
zergzorg wants to merge 5 commits into
tscircuit:mainfrom
zergzorg:codex/invalid-empty-response-guidance-30

Conversation

@zergzorg
Copy link
Copy Markdown

@zergzorg zergzorg commented May 21, 2026

Summary

  • keeps the existing raw object guidance for accidental return { ... } route handlers
  • adds early guards for null, undefined, primitive, symbol, and function route returns so they produce the actionable ctx.json(...) guidance before response serialization fails
  • preserves valid custom SerializableToResponse objects so supported response wrappers still pass through
  • adds regression coverage for raw object, null, undefined, primitive, symbol, function, and custom serializable-response paths

/claim #30

Validation

  • npm run build
  • npm test -- tests/errors/do-not-allow-raw-json.test.ts
  • npm run lint -- --ignore-path .gitignore
  • npm run typecheck
  • git diff --check

Notes

This is a narrow diagnostic follow-up for #30. It does not change valid Response, ctx.json(...), or custom serializable response return paths.

@zergzorg
Copy link
Copy Markdown
Author

Follow-up after checking fresh #30 attempts:

  • Added the same actionable guidance path for raw primitive route returns (string, number, boolean, bigint), not only object/null/undefined returns.
  • The guard now rejects anything that is not a Response or WinterSpec serializable response before serialization tries to inspect it.
  • Added focused AVA coverage for the primitive return cases.

Validation:

  • npx ava tests/errors/do-not-allow-raw-json.test.ts
  • npm run build
  • npx prettier --check src/middleware/with-response-object-check.ts tests/errors/do-not-allow-raw-json.test.ts
  • git diff --check

@zergzorg
Copy link
Copy Markdown
Author

Follow-up after the latest #30 attempts:

  • Added regression coverage for raw symbol and raw function route returns.
  • This uses the existing validation path from this PR and keeps the scope to actionable guidance for non-Response handler returns.

Validation: npm test -- tests/errors/do-not-allow-raw-json.test.ts

Signed-off-by: zergzorg <kaluga@me.com>
@zergzorg
Copy link
Copy Markdown
Author

Follow-up regression coverage pushed in 8cd0b85:

  • added a test that custom SerializableToResponse objects still pass through the raw-return guard
  • keeps the invalid raw primitive/object/null coverage while protecting the supported custom response path

Validation:

  • npm run build
  • npm test -- tests/errors/do-not-allow-raw-json.test.ts
  • git diff --check
  • GitHub build is passing on the new head

@zergzorg
Copy link
Copy Markdown
Author

Follow-up clarification pushed in d75113e after re-checking newer same-issue guidance PRs:

  • the invalid route-return error now recommends ctx.json(value) instead of implying only object literals are valid JSON responses
  • the message now covers raw primitive/null/undefined returns and still points users toward Response-compatible returns
  • tests now assert against the shared error-message constant so future wording changes stay aligned with the middleware

Validation:

  • npm test -- tests/errors/do-not-allow-raw-json.test.ts
  • npm run build
  • npm run lint -- src/middleware/with-response-object-check.ts tests/errors/do-not-allow-raw-json.test.ts
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant