mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-04-20 03:43:47 +01:00
feat(registry): print more error info
Previously, only the root error's Display was printed. Now we print Display of the root and every parent error's as well.
This commit is contained in:
parent
308320602f
commit
86a111cf83
3 changed files with 28 additions and 6 deletions
|
@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
### Changed
|
||||||
|
- Print more error info by @daimond113
|
||||||
|
|
||||||
## [0.2.0] - 2025-02-22
|
## [0.2.0] - 2025-02-22
|
||||||
### Added
|
### Added
|
||||||
- Support deprecating and yanking packages by @daimond113
|
- Support deprecating and yanking packages by @daimond113
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::{get_token_from_req, AuthImpl, UserId},
|
auth::{get_token_from_req, AuthImpl, UserId},
|
||||||
error::ReqwestErrorExt,
|
error::{display_error, ReqwestErrorExt},
|
||||||
};
|
};
|
||||||
use actix_web::{dev::ServiceRequest, Error as ActixError};
|
use actix_web::{dev::ServiceRequest, Error as ActixError};
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
@ -46,14 +46,14 @@ impl AuthImpl for GitHubAuth {
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"failed to get user: {}",
|
"failed to get user info: {}",
|
||||||
response.into_error().await.unwrap_err()
|
display_error(response.into_error().await.unwrap_err())
|
||||||
);
|
);
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("failed to get user: {e}");
|
tracing::error!("failed to send user info request: {}", display_error(e));
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -61,7 +61,7 @@ impl AuthImpl for GitHubAuth {
|
||||||
let user_id = match response.json::<UserResponse>().await {
|
let user_id = match response.json::<UserResponse>().await {
|
||||||
Ok(resp) => resp.user.id,
|
Ok(resp) => resp.user.id,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("failed to get user: {e}");
|
tracing::error!("failed to parse user info response: {}", display_error(e));
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use actix_web::{body::BoxBody, HttpResponse, ResponseError};
|
use actix_web::{body::BoxBody, HttpResponse, ResponseError};
|
||||||
use pesde::source::git_index::errors::{ReadFile, RefreshError, TreeError};
|
use pesde::source::git_index::errors::{ReadFile, RefreshError, TreeError};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::error::Error;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
@ -66,7 +67,7 @@ impl ResponseError for RegistryError {
|
||||||
error: format!("archive is invalid: {e}"),
|
error: format!("archive is invalid: {e}"),
|
||||||
}),
|
}),
|
||||||
e => {
|
e => {
|
||||||
tracing::error!("unhandled error: {e:?}");
|
tracing::error!("unhandled error: {}", display_error(e));
|
||||||
HttpResponse::InternalServerError().finish()
|
HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,3 +88,20 @@ impl ReqwestErrorExt for reqwest::Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn display_error<E: Error>(err: E) -> String {
|
||||||
|
let mut causes = vec![];
|
||||||
|
let mut source = err.source();
|
||||||
|
while let Some(src) = source {
|
||||||
|
causes.push(format!("\t- {src}"));
|
||||||
|
source = src.source();
|
||||||
|
}
|
||||||
|
format!(
|
||||||
|
"{err}{}",
|
||||||
|
if causes.is_empty() {
|
||||||
|
"".into()
|
||||||
|
} else {
|
||||||
|
format!("\n{}", causes.join("\n"))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue