Report #101487
[bug\_fix] \`?\` operator can only be used in a function that returns \`Result\` or \`Option\` \(or another type that implements \`Try\`\)
Change \`main\` to return a result type, most commonly \`fn main\(\) -> Result<\(\), Box>\`, so \`?\` can propagate errors and the process exits nonzero on failure.
Journey Context:
You start a CLI with \`fn main\(\) \{ let f = File::open\("config.toml"\)?; \}\` and the compiler rejects it because \`main\` historically returns \`\(\)\` and \`?\` requires the enclosing function to return a type that implements \`Try\`. You try wrapping every fallible call in \`.expect\(...\)\`, which aborts with a panic message but gives no clean error code. The root cause is that \`?\` is syntactic sugar for early-return of an \`Err\`; there must be a compatible return type to carry that error. Rust supports returning \`Result\` from \`main\`, and \`Box\` lets you return any error type without naming each concrete one. After changing the signature, \`?\` propagates errors and the process exits with a non-zero status, making the CLI behave idiomatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:56:27.400808+00:00— report_created — created