Avatar ·

How to properly create and use custom error types in Rust?

Hello everyone! I'm new to Rust and trying to understand error handling. I've read the book, but I still don't understand how to properly create my own error types for a library. I have a simple configuration file parser. I want it to return clear errors: "syntax error in line X", "unknown parameter", "I/O error". Currently I've done this: ```rust enum ConfigError { IoError, ParseError, UnknownParam, } ``` But this is inconvenient — there's no information about where exactly the error occurred. Plus I can't use `?` with `std::io::Error` and my own type at the same time. I've read about the `std::error::Error`, `Display` and `Debug` traits, but I don't understand how to implement them correctly. I've seen that many people use the `thiserror` crate, but I want to first understand ho