Skip to main content

bail/
bail.rs

1// Copyright (C) 2026 Kan-Ru Chen <kanru@kanru.info>
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5use scoped_error::{Error, bail, expect_error};
6
7fn connect(url: &str) -> Result<String, Error> {
8    expect_error("Failed to connect to target", || {
9        if !url.is_empty() {
10            return Ok("connected".to_string());
11        }
12        bail!("invalid URL [{}]", url);
13    })
14}
15
16fn main() -> Result<(), Error> {
17    expect_error("This program will error", || {
18        connect("")?;
19        Ok(())
20    })
21}