fed-sx-m2: Step 8f — live HTTP delivery dispatch (+ 10 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s
Closes Step 8 (except 8b-timer which still gates on Blockers #3 send_after). New next/kernel/dispatch_http.erl wires the BIF landed in Step 8e into a delivery_worker-shaped dispatch_fn. dispatch_http API: make_dispatch_fn(PeerId, Cfg) -> fun((Activity) -> ok | {error,_}) dispatch(Url, Activity, Cfg) -> ok | {error, _} inbox_url(BaseUrl, PeerAtom) -> <Base>/actors/<peer>/inbox resolve_peer_url(PeerId, Cfg) -> {ok, Base} | {error, no_peer_url} content_type/0 -> <<"application/vnd.fed-sx.activity">> Peer URL resolution composes: {peer_url, [{PeerId, BaseUrl}, ...]} static map (tests) {peer_url_fn, fun ((PeerId) -> {ok, Url} | not_found)} closure (Step 10c peer_actors) Result mapping at dispatch/3: 2xx -> ok (worker drops the entry) non-2xx -> {error, {status, N}} (worker bumps attempt) resolver miss -> {error, no_peer_url} transport -> {error, Reason} (BIF re-raises, caught here) httpc:request/4 BIF wrapper updated to catch host Eval_error via SX `guard` and re-raise as Erlang `error:{network, ReasonBinary}` so callers can handle it through standard try/catch — previously the host exception bubbled past the Erlang try/catch surface (which only handles er-thrown? / er-errored? / er-exited? markers). Subtle Erlang-port note documented in dispatch/3: this port's try/catch requires a literal class atom (`error:Reason`); the generic `Class:Reason` syntax is not supported. dispatch_http catches `error:Reason` only, which is what the BIF re-raise produces. Test: next/tests/dispatch_http.sh 10/10 against background python3 http.server (always-200 handler): - module loads - inbox_url builds /actors/X/inbox - static :peer_url map resolves - missing peer -> {error, no_peer_url} - live POST -> 200 -> ok - closure path -> ok - closure on missing peer -> {error, no_peer_url} - closed port -> {error, _} - delivery_worker drains the queue via the live closure - :peer_url_fn closure path resolves No-regression gates green: Erlang conformance 761/761, httpc_request 10/10, http_listen_bif 5/5, delivery_worker 17/17, delivery_retry 11/11, delivery_dispatch 7/7. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1607,8 +1607,8 @@
|
||||
;;
|
||||
;; Returns a 4-tuple {ok, StatusInt, HeadersProplist, BodyBinary}.
|
||||
;; The native primitive raises Eval_error on DNS / connect / bad URL;
|
||||
;; that surfaces as an Erlang error marker the caller can catch via
|
||||
;; Erlang try/catch.
|
||||
;; we catch the host exception here and re-raise as an Erlang error
|
||||
;; marker so callers can use try/catch error:{network, _} -> _ end.
|
||||
(define
|
||||
er-bif-httpc-request
|
||||
(fn
|
||||
@@ -1641,14 +1641,26 @@
|
||||
(er-binary? body) (list->string (map integer->char (get body :bytes)))
|
||||
(er-nil? body) ""
|
||||
:else (raise (er-mk-error-marker (er-mk-atom "badarg"))))))
|
||||
(let
|
||||
((resp (http-request method-str url-str headers-dict body-str)))
|
||||
(er-mk-tuple
|
||||
(list
|
||||
(er-mk-atom "ok")
|
||||
(get resp :status)
|
||||
(er-of-sx-deep (get resp :headers))
|
||||
(er-mk-binary (map char->integer (string->list (get resp :body)))))))))))
|
||||
(let ((resp-ref (list nil)) (err-ref (list nil)))
|
||||
(guard (c (:else (set-nth! err-ref 0 c)))
|
||||
(set-nth! resp-ref 0
|
||||
(http-request method-str url-str headers-dict body-str)))
|
||||
(cond
|
||||
(not (= (nth err-ref 0) nil))
|
||||
;; Host error -> Erlang error:{network, ReasonBinary}
|
||||
(raise (er-mk-error-marker
|
||||
(er-mk-tuple (list
|
||||
(er-mk-atom "network")
|
||||
(er-mk-binary (map char->integer
|
||||
(string->list (str (nth err-ref 0)))))))))
|
||||
:else
|
||||
(let ((resp (nth resp-ref 0)))
|
||||
(er-mk-tuple
|
||||
(list
|
||||
(er-mk-atom "ok")
|
||||
(get resp :status)
|
||||
(er-of-sx-deep (get resp :headers))
|
||||
(er-mk-binary (map char->integer (string->list (get resp :body)))))))))))))
|
||||
|
||||
;; Register everything at load time.
|
||||
(define
|
||||
|
||||
Reference in New Issue
Block a user