Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
131 changes: 0 additions & 131 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/collect_links/collect_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async fn main() -> Result<(), Box<RequestError>> {
.skip_missing_inputs(false) // don't skip missing inputs? (default=false)
.skip_hidden(false) // skip hidden files? (default=true)
.skip_ignored(false) // skip files that are ignored by git? (default=true)
.use_html5ever(false) // use html5ever for parsing? (default=false)
.collect_links(inputs) // base url or directory
.collect::<Result<Vec<_>, _>>()
.await?;
Expand Down
5 changes: 0 additions & 5 deletions fixtures/TEST_REPETITION_1.txt

This file was deleted.

5 changes: 0 additions & 5 deletions fixtures/TEST_REPETITION_2.txt

This file was deleted.

16 changes: 10 additions & 6 deletions lychee-bin/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use tokio_stream::wrappers::ReceiverStream;

use lychee_lib::InputSource;
use lychee_lib::RequestError;
use lychee_lib::Status;
use lychee_lib::archive::Archive;
use lychee_lib::{Client, ErrorKind, Request, Response, Uri};
use lychee_lib::{ResponseBody, Status};

use crate::formatters::stats::ResponseStats;
use crate::formatters::suggestion::Suggestion;
Expand Down Expand Up @@ -213,12 +213,14 @@ async fn check_url(client: &Client, request: Request) -> Response {
// Request was not cached; run a normal check
let uri = request.uri.clone();
let source = request.source.clone();
let span = request.span;
client.check(request).await.unwrap_or_else(|e| {
log::error!("Error checking URL {uri}: Cannot parse URL to URI: {e}");
Response::new(
uri.clone(),
Status::Error(ErrorKind::InvalidURI(uri.clone())),
source.into(),
span,
)
})
}
Expand Down Expand Up @@ -262,7 +264,12 @@ async fn handle(
Status::from_cache_status(v.value().status, &accept)
};

return Ok(Response::new(uri.clone(), status, request.source.into()));
return Ok(Response::new(
uri.clone(),
status,
request.source.into(),
request.span,
));
}

let response = check_url(client, request).await;
Expand Down Expand Up @@ -304,10 +311,7 @@ fn get_failed_urls(stats: &mut ResponseStats) -> Vec<(InputSource, Url)> {
stats
.error_map
.iter()
.flat_map(|(source, set)| {
set.iter()
.map(move |ResponseBody { uri, status: _ }| (source, uri))
})
.flat_map(|(source, set)| set.iter().map(move |body| (source, &body.uri)))
.filter_map(|(source, uri)| {
if uri.is_data() || uri.is_mail() || uri.is_file() {
None
Expand Down
27 changes: 24 additions & 3 deletions lychee-bin/src/formatters/stats/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ fn markdown_response(response: &ResponseBody) -> Result<String> {
response.uri,
);

if let Some(span) = response.span {
formatted = format!("{formatted} at {span}");
}

if let Status::Ok(StatusCode::OK) = response.status {
// Don't print anything else if the status code is 200.
// The output gets too verbose then.
Expand Down Expand Up @@ -169,41 +173,58 @@ impl StatsFormatter for Markdown {

#[cfg(test)]
mod tests {
use std::num::NonZeroUsize;

use http::StatusCode;
use lychee_lib::RawUriSpan;
use lychee_lib::{CacheStatus, ResponseBody, Status, Uri};

use crate::formatters::stats::get_dummy_stats;

use super::*;

const SPAN: Option<RawUriSpan> = Some(RawUriSpan {
line: NonZeroUsize::MIN,
column: NonZeroUsize::MIN,
});

#[test]
fn test_markdown_response_ok() {
let response = ResponseBody {
uri: Uri::try_from("http://example.com").unwrap(),
status: Status::Ok(StatusCode::OK),
span: SPAN,
};
let markdown = markdown_response(&response).unwrap();
assert_eq!(markdown, "* [200] <http://example.com/>");
assert_eq!(markdown, "* [200] <http://example.com/> at 1:1");
}

#[test]
fn test_markdown_response_cached_ok() {
let response = ResponseBody {
uri: Uri::try_from("http://example.com").unwrap(),
status: Status::Cached(CacheStatus::Ok(StatusCode::OK)),
span: SPAN,
};
let markdown = markdown_response(&response).unwrap();
assert_eq!(markdown, "* [200] <http://example.com/> | OK (cached)");
assert_eq!(
markdown,
"* [200] <http://example.com/> at 1:1 | OK (cached)"
);
}

#[test]
fn test_markdown_response_cached_err() {
let response = ResponseBody {
uri: Uri::try_from("http://example.com").unwrap(),
status: Status::Cached(CacheStatus::Error(Some(StatusCode::BAD_REQUEST))),
span: SPAN,
};
let markdown = markdown_response(&response).unwrap();
assert_eq!(markdown, "* [400] <http://example.com/> | Error (cached)");
assert_eq!(
markdown,
"* [400] <http://example.com/> at 1:1 | Error (cached)"
);
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion lychee-bin/src/formatters/stats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn get_dummy_stats() -> OutputStats {
.try_into()
.unwrap(),
status: Status::Ok(StatusCode::NOT_FOUND),
span: None,
}]),
)]);

Expand All @@ -121,6 +122,7 @@ fn get_dummy_stats() -> OutputStats {
HashSet::from([ResponseBody {
uri: "https://redirected.dev".try_into().unwrap(),
status: Status::Redirected(StatusCode::OK, redirects),
span: None,
}]),
)]);

Expand Down Expand Up @@ -176,7 +178,7 @@ mod tests {
fn make_test_response(url_str: &str, source: InputSource) -> Response {
let uri = Uri::from(make_test_url(url_str));

Response::new(uri, Status::Error(ErrorKind::EmptyUrl), source)
Response::new(uri, Status::Error(ErrorKind::EmptyUrl), source, None)
}

#[test]
Expand Down
Loading