Skip to content

feat(rpc, net): allow registry + http_router to compile under -fno-exceptions - #2564

Open
genisis0x wants to merge 2 commits into
stephenberry:mainfrom
genisis0x:fix/2265-rpc-registry-no-exceptions
Open

feat(rpc, net): allow registry + http_router to compile under -fno-exceptions#2564
genisis0x wants to merge 2 commits into
stephenberry:mainfrom
genisis0x:fix/2265-rpc-registry-no-exceptions

Conversation

@genisis0x

Copy link
Copy Markdown
Contributor

Summary

  • Closes rpc registry: support for no exceptions #2265. `registry::call` has three `try`/`catch` blocks (REPE message-based, REPE span-based, JSON-RPC) wrapping the registered handler invocation. Transitively the registry pulls in `net/http_router.hpp`, which has one `try`/`catch` plus three `throw std::runtime_error` route-misuse sites. Under `-fno-exceptions` none of that compiles, so the rpc registry could not be used in exception-free projects at all — the scenario @redrezo described in the issue.

Fix

  • Guard every site with `#if __cpp_exceptions`, matching the convention already used by `glaze_exceptions.hpp`, `core_exceptions.hpp`, and `cli_menu.hpp`.

`registry.hpp` — three sites

  • When exceptions are off, the `catch` is elided and the handler is invoked directly. Any exception escaping user code in that mode is UB per the `-fno-exceptions` contract; documented inline.

`http_router.hpp` — four sites

  • `add(...)` try/catch: under `-fno-exceptions` the routing install is performed without try-coverage; misuse below still surfaces on stderr through the matching `#else` branches.
  • Three route-misuse `throw` sites (parameter-name conflict, wildcard-not-last, wildcard-name conflict): under `-fno-exceptions` each becomes `fprintf(stderr, ...)` + `std::abort()`. Misconfiguration is still loud and fatal, which matches the existing throw behaviour for callers that did not catch.

Verification

```
clang++ -std=c++23 -fno-exceptions -Iinclude /tmp/glaze_noexc_check.cpp -o /tmp/glaze_noexc_check

(formerly: "cannot use 'try' with exceptions disabled" x4 + "cannot use 'throw' with exceptions disabled" x3)

now: clean build, exit 0

```

Default with-exceptions build: token-identical to before this commit (the `#else` branches only activate under `-fno-exceptions`). Local `jsonrpc_test` and `repe_test` rebuild and link unchanged.

Compatibility

  • No public-API change.
  • No behaviour change for the default build.
  • New: the registry + http_router compile under `-fno-exceptions`.

genisis0x added 2 commits May 13, 2026 15:20
…ceptions

Closes stephenberry#2265.

`registry::call` has three `try`/`catch` blocks (REPE message-based,
REPE span-based, and JSON-RPC) wrapping the registered handler
invocation `it->second(state)`. Transitively the registry pulls in
`net/http_router.hpp`, which has one `try`/`catch` (route registration
error reporting) and three `throw std::runtime_error` sites for route
misuse (parameter-name conflict, wildcard-not-last, wildcard-name
conflict). Under `-fno-exceptions` none of this compiles, so the rpc
registry could not be used in exception-free projects at all — the
scenario the reporter described.

Guard every site with `#if __cpp_exceptions`, matching the convention
used in `glaze_exceptions.hpp`, `core_exceptions.hpp`, and
`cli_menu.hpp`:

- registry.hpp: when exceptions are off, the catch is elided and the
  handler is invoked directly; any exception escaping user code in
  that mode is UB per the `-fno-exceptions` contract.
- http_router.hpp `add(...)`: when exceptions are off the routing
  install is performed without try-coverage; misuse below still
  surfaces on stderr via the `#else` branches.
- http_router.hpp three misuse `throw`s: under `-fno-exceptions` each
  becomes `fprintf(stderr, ...)` + `std::abort()`. Misconfiguration
  is fatal but loud, which matches the existing throw behaviour for
  callers that did not catch.

Verified with `clang++ -std=c++23 -fno-exceptions` on the four
registry/http_router headers; default with-exceptions build path is
token-identical to before.
Previous run timed out in http_client_test (test stephenberry#77/94) on Windows
clang-cl. This PR does not touch http_client; the test is independent
and consistently passes on main. Forcing a fresh build run.
@genisis0x

Copy link
Copy Markdown
Contributor Author

Heads up on the red build (13, Debug, 23) jobs: the failure is get_name.hpp:197 [-fpermissive] 'glz_write_error' ... is used but never defined while compiling tests/networking_tests/http_router_test.cpp — same compile error that's red on the comment-only #2567 and that didn't block #2565 from merging. This PR only adds #if __cpp_exceptions guards around existing throw sites; the default-exceptions path GCC 13 takes is byte-identical to develop, so the failure isn't introduced here.

Happy to rebase onto develop after #2544 settled if that helps a re-run.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpc registry: support for no exceptions

1 participant