Pogr-io / pogr_tracing_rs

pogr_tracing_rs is a Crate to allow log collection from the tracing crate, easy and simple.
https://pogr.io
MIT License
0 stars 0 forks source link

not recommended to use unwrap() in production code (Rust Programming Language[JokNavi]) #5

Open Bioblaze opened 8 months ago

Bioblaze commented 8 months ago

Also it's generally not recommended to use unwrap() in production code. use error handling by using the Result<T, E> type as your return type or use expect where needed

pub async fn new(init_endpoint: Option<String>, logs_endpoint: Option<String>) -> Self {
        let client = Client::new();

        let service_name = env::var("SERVICE_NAME").unwrap_or_else(|_| env::current_exe().unwrap().file_name().unwrap().to_str().unwrap().to_owned());
        let environment = env::var("ENVIRONMENT").unwrap_or_else(|_| "development".to_owned());
        let service_type = env::var("SERVICE_TYPE").unwrap_or_else(|_| "service".to_owned());

...rest of function...

Could you shed some more light on why you used unwrap here? i would recommend you use a custom error type enum perhaps with variants that explain why the method returned an error