Skip to content

Facades present C's call shape: the user must learn "check every setopt against CURLE_OK", "declare the sink before the handle", "build the handle in a helper" from compile errors #3128

Done

Description

@ehartford

Part of #3115. Ceremony report (CLAUDE.md "Ceremony is a design defect").

The code as a person reads it: configure a request, send it.
What they had to write: every easy.setopt(...) result compared against CURLE_OK or perform() does not compile; the write-callback's sink declared before the handle; the handle made in a helper function (let made = Easy.new(); if made.is_none(): ...) rather than in main.
Why: the guardrails are right (Law 4: an unchecked setopt may leave the handle half-configured; the sink must outlive the handle), but the facade presents libcurl's C shape, so the guardrails surface as rules to discover.
What it should look like:

var easy = Easy.new()?
easy.url(u)?.header_list(h)?.post(body)?
let resp = easy.perform()?

The ok CURLE_OK contract already says a setter fails by status: presented as Result, ? is the check (no comparison to remember). A retained sink can be owned by the transfer (perform returns the body) so there is no declaration order to get right.
What has to change: facade presentation generates typed per-option setters (url, timeout_ms, header_list) from the variadic cases, each returning Result[(), E]; a common callback shape (collect into a buffer) gets a presented form. Investigate the helper-function rule separately: if main cannot hold the handle, that is a defect of its own (record why here).

Count: the libcurl release UAT and every libcurl user pay this today.

Activity

  1. ehartford commented on Nov 24, 2026

    @ehartford
    ContributorAuthor

    The one part of this that needed no ruling, checked on main a784b42: a handle can be made in main. With a plain resource (from / drop, one lent operation), all four of these compile and run in fn main:

    let e = Easy.new().unwrap()
    
    let made = Easy.new()
    if made.is_none(): …; return
    let e = made.unwrap()
    
    match Easy.new():
        Some(e) => …
        None => …
    

    let e = Easy.new()? does not, for the ordinary reason: ? on an Option needs an Option return (§10.2), and main has none. So the helper function in the libcurl program was not forced by the handle. If it was forced by the retained write callback (the handle is ephemeral while a retention is live), that is the declare-order cost named in #3120's brief, not a separate defect.

    Found while probing this and fixed separately: fn main -> Result[Unit, E] returning an Err exited with status 0, and with a larger Result failed in code generation. A program that writes fn main -> Result[…] to use ? on its setters got no report of a failure.

    What is left here is the presentation itself (typed per-option setters returning Result, a presented collect-into-buffer callback), which is facade surface and yours to shape. Labelling human attn needed.

  2. ehartford commented on Nov 25, 2026

    @ehartford
    ContributorAuthor

    Ruled by Eric, 2026-11-25 (answers to briefs.md).

    9a: C. setopt(K, value) returning Result is unconditional (it is the ok contract applied). Per-option setters are switched on by one line on the contract, not per case. The issue's example easy.url(u)?.header_list(h)? does not work with setters returning Result[(), E]: either the setters return the receiver or the example changes, and the §16.2b.5 sentence has to choose; I bring that sentence. 9b (collect-into-buffer callback): not in scope now. Label removed.

  3. added a commit that references this issue on Nov 27, 2026
    2e00577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions