Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lychee-bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ mod cli {
.failure()
.code(2)
.stdout(contains(
r#"[404] https://github.com/mre/idiomatic-rust-doesnt-exist-man | Rejected status code (this depends on your "accept" configuration): Not Found"#
r#"[404] https://github.com/mre/idiomatic-rust-doesnt-exist-man | Rejected status code: 404 Not Found (configurable with "accept" option)"#
))
.stderr(contains(
"There were issues with GitHub URLs. You could try setting a GitHub token and running lychee again.",
Expand Down Expand Up @@ -1285,7 +1285,7 @@ The config file should contain every possible key for documentation purposes."
mock_server_no_content.uri()
)))
.stderr(contains(format!(
"[429] {}/ | Rejected status code (this depends on your \"accept\" configuration): Too Many Requests\n",
"[429] {}/ | Rejected status code: 429 Too Many Requests (configurable with \"accept\" option)",
mock_server_too_many_requests.uri()
)));

Expand Down Expand Up @@ -1343,11 +1343,11 @@ The config file should contain every possible key for documentation purposes."
.failure()
.code(2)
.stdout(contains(format!(
r#"[418] {}/ | Rejected status code (this depends on your "accept" configuration): I'm a teapot"#,
r#"[418] {}/ | Rejected status code: 418 I'm a teapot (configurable with "accept" option)"#,
mock_server_teapot.uri()
)))
.stdout(contains(format!(
r#"[500] {}/ | Rejected status code (this depends on your "accept" configuration): Internal Server Error"#,
r#"[500] {}/ | Rejected status code: 500 Internal Server Error (configurable with "accept" option)"#,
mock_server_server_error.uri()
)));

Expand Down Expand Up @@ -1393,7 +1393,7 @@ The config file should contain every possible key for documentation purposes."
.failure()
.code(2)
.stdout(contains(format!(
r#"[200] {}/ | Rejected status code (this depends on your "accept" configuration): OK"#,
r#"[200] {}/ | Rejected status code: 200 OK (configurable with "accept" option)"#,
mock_server_200.uri()
)));

Expand Down
32 changes: 25 additions & 7 deletions lychee-lib/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ pub enum ErrorKind {
InvalidStatusCode(u16),

/// The given status code was not accepted (this depends on the `accept` configuration)
#[error(r#"Rejected status code (this depends on your "accept" configuration)"#)]
#[error(
r#"Rejected status code: {code} {reason} (configurable with "accept" option)"#,
code = .0.as_str(),
reason = .0.canonical_reason().unwrap_or("Unknown status code")
)]
RejectedStatusCode(StatusCode),

/// Regex error
Expand Down Expand Up @@ -202,12 +206,9 @@ impl ErrorKind {
// Get detailed, actionable error analysis
Some(utils::reqwest::analyze_error_chain(e))
}
ErrorKind::RejectedStatusCode(status) => Some(
status
.canonical_reason()
.unwrap_or("Unknown status code")
.to_string(),
),
ErrorKind::RejectedStatusCode(status) => status
.is_redirection()
.then_some(r#"Redirects may have been limited by "max-redirects"."#.to_string()),
ErrorKind::GithubRequest(e) => {
if let octocrab::Error::GitHub { source, .. } = &**e {
Some(source.message.clone())
Expand Down Expand Up @@ -514,3 +515,20 @@ impl From<Infallible> for ErrorKind {
unreachable!()
}
}

#[cfg(test)]
mod tests {
use crate::ErrorKind;
#[test]
fn test_error_kind_details() {
// Test rejected status code
let status_error = ErrorKind::RejectedStatusCode(http::StatusCode::NOT_FOUND);
assert!(status_error.to_string().contains("Not Found"));

// Test redirected status code
let redir_error = ErrorKind::RejectedStatusCode(http::StatusCode::MOVED_PERMANENTLY);
assert!(redir_error.details().is_some_and(|x| x.contains(
"Redirects may have been limited by \"max-redirects\""
)));
}
}
23 changes: 0 additions & 23 deletions lychee-lib/src/utils/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,26 +397,3 @@ fn fallback_reqwest_analysis(error: &reqwest::Error) -> String {
format!("Request failed: {error}")
}
}

#[cfg(test)]
mod tests {
use crate::ErrorKind;

/// Test that `ErrorKind::details()` properly uses the new analysis
#[test]
fn test_error_kind_details_integration() {
// Test rejected status code
let status_error = ErrorKind::RejectedStatusCode(http::StatusCode::NOT_FOUND);
assert_eq!(status_error.details(), Some("Not Found".to_string()));

// Test that network request errors would use analyze_error_chain
// (actual reqwest::Error creation is complex, so we test the integration point)

// For other error types, ensure they still work
let test_error = ErrorKind::EmptyUrl;
assert_eq!(
test_error.details(),
Some("Empty URL found. Check for missing links or malformed markdown".to_string())
);
}
}