-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_from_thiserror.rs
More file actions
25 lines (21 loc) · 825 Bytes
/
Copy pathmigrate_from_thiserror.rs
File metadata and controls
25 lines (21 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
//
// SPDX-License-Identifier: MIT
//! Migration from thiserror to masterror - incremental steps.
use masterror::{AppError, AppResult, field};
fn main() {
println!("Migration from thiserror to masterror");
println!();
println!("Step 1: Change `thiserror::Error` -> `masterror::Error`");
println!("Step 2: Add #[app_error(...)] for HTTP/gRPC mapping");
println!("Step 3: Use AppError with structured metadata");
println!();
match find_user("alice") {
Ok(()) => println!("User found"),
Err(e) => println!("Error: {e}")
}
}
fn find_user(user_id: &str) -> AppResult<()> {
Err(AppError::not_found(format!("User {user_id} not found"))
.with_field(field::str("user_id", user_id.to_string())))
}