1
1
use std:: str:: FromStr ;
2
2
3
- use tl:: HTMLTag ;
3
+ use tl:: { HTMLTag , Parser } ;
4
4
use tracing:: { instrument, warn} ;
5
5
use url:: Url ;
6
6
@@ -44,7 +44,7 @@ impl SimpleHtml {
44
44
. iter ( )
45
45
. filter_map ( |node| node. as_tag ( ) )
46
46
. filter ( |link| link. name ( ) . as_bytes ( ) == b"a" )
47
- . map ( |link| Self :: parse_anchor ( link) )
47
+ . map ( |link| Self :: parse_anchor ( link, dom . parser ( ) ) )
48
48
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
49
49
// While it has not been positively observed, we sort the files
50
50
// to ensure we have a defined ordering. Otherwise, if we rely on
@@ -70,14 +70,14 @@ impl SimpleHtml {
70
70
}
71
71
72
72
/// Parse a [`File`] from an `<a>` tag.
73
- fn parse_anchor ( link : & HTMLTag ) -> Result < File , Error > {
73
+ fn parse_anchor ( link : & HTMLTag , parser : & Parser ) -> Result < File , Error > {
74
74
// Extract the href.
75
75
let href = link
76
76
. attributes ( )
77
77
. get ( "href" )
78
78
. flatten ( )
79
79
. filter ( |bytes| !bytes. as_bytes ( ) . is_empty ( ) )
80
- . ok_or ( Error :: MissingHref ) ?;
80
+ . ok_or ( Error :: MissingHref ( link . inner_text ( parser ) . to_string ( ) ) ) ?;
81
81
let href = std:: str:: from_utf8 ( href. as_bytes ( ) ) ?;
82
82
83
83
// Extract the hash, which should be in the fragment.
@@ -187,8 +187,8 @@ pub enum Error {
187
187
#[ error( transparent) ]
188
188
HtmlParse ( #[ from] tl:: ParseError ) ,
189
189
190
- #[ error( "Missing href attribute on anchor link" ) ]
191
- MissingHref ,
190
+ #[ error( "Missing href attribute on anchor link: `{0}` " ) ]
191
+ MissingHref ( String ) ,
192
192
193
193
#[ error( "Expected distribution filename as last path component of URL: {0}" ) ]
194
194
MissingFilename ( String ) ,
0 commit comments