Skip to content

Conversation

@thomas-zahner
Copy link
Member

@thomas-zahner thomas-zahner commented Jan 14, 2026

Fixes #1769. Previously lychee example.com --accept 123.. lead to Error: invalid status code.

In the process I've eliminated some primitive obsession with u16 where we actually meant StatusCode. This also improved error handling with invalid values in the lychee cache file. See commit messages for more information.

Improves the error messages overall. For example prviously:

error: invalid value '123..1234' for '--cache-exclude-status <CACHE_EXCLUDE_STATUS>': failed to parse accept range: no range pattern found

Now:

error: invalid value '123..1234' for '--cache-exclude-status <CACHE_EXCLUDE_STATUS>': failed to parse range: values must represent valid status codes between 100 and 999 (inclusive)

Remove unnecessary distinction between StatusCodeExcluder and
StatusCodeSelector.
This change also improves error handling with invalid status code values
in the lychee cache file. Below is an example with an unrepresentable
status code value of 20.

Previously it was converted to "Error (cached)":

[http://example.com/]:
      [20] https://example.com/foobar | Error (cached)

Now it is detected as follows:

    [WARN] Error while loading cache: CSV deserialize error: record 18 (line: 19, byte: 961): invalid status code value, expected the value to be >= 100 and <= 999. Continuing without.
Previously an invalid range for --cache-exclude-status contained
"failed to parse accept range" which is rather confusing.
@thomas-zahner thomas-zahner requested a review from mre January 14, 2026 10:14
};
if captures.get(2).is_none() {
return Self::new_from(start, u16::MAX);
return Self::new(start, MAX);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bugfix with the 123.. example, it now ends at 999

@thomas-zahner
Copy link
Member Author

@HadrienG2 & @katrinafyi feel free to take a look and review

Copy link
Member

@katrinafyi katrinafyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks very reasonable. always happy to see deduplication. miniscule comments :)

Reuse constant & document regex
Comment on lines +67 to +84
Ok(code) => {
let code = StatusCode::from_u16(code).map_err(|_| {
use serde::de::Error;
D::Error::custom(
"invalid status code value, expected the value to be >= 100 and <= 999",
)
})?;
if code.is_success() {
// classify successful status codes as cache status success
// Does not account for status code overrides passed through
// the 'accept' flag. Instead, this is handled at a higher level
// when the cache status is converted to a status.
Ok(CacheStatus::Ok(code))
} else {
// classify redirects, client errors, & server errors as cache status error
Ok(CacheStatus::Error(Some(code)))
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done

@mre
Copy link
Member

mre commented Jan 14, 2026

image

Superb job and much cleaner. Neat!

@mre mre merged commit db63437 into lycheeverse:master Jan 14, 2026
7 checks passed
@mre mre mentioned this pull request Jan 14, 2026
@mre mre mentioned this pull request Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--accept doesn't accept the same values as --cache-exclude-status

3 participants