context/context.rs
1// Copyright (C) 2026 Kan-Ru Chen <kanru@kanru.info>
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5use std::io;
6
7use scoped_error::{Context, Error, expect_error};
8
9fn parse_url(url: &str) -> io::Result<()> {
10 let _ = url;
11 Err(io::Error::other("invalid URL format"))
12}
13
14fn connect(url: &str) -> Result<String, Error> {
15 parse_url(url).context("failed to parse url")?;
16 Ok("hello".to_string())
17}
18
19fn main() -> Result<(), Error> {
20 expect_error("This program will error", || {
21 connect("")?;
22 Ok(())
23 })
24}