Skip to content

User hints#2021

Merged
thomas-zahner merged 16 commits into
lycheeverse:masterfrom
thomas-zahner:user-hints
Apr 29, 2026
Merged

User hints#2021
thomas-zahner merged 16 commits into
lycheeverse:masterfrom
thomas-zahner:user-hints

Conversation

@thomas-zahner

@thomas-zahner thomas-zahner commented Feb 2, 2026

Copy link
Copy Markdown
Member

Sorry if this isn't the right place to discuss this, but I always found the message (this depends on your "accept" configuration) on every line a bit noisy. Maybe we should put it at the end, as we do with the GitHub token hint.

[stdin]:
     [301] https://mock.httpstatus.io/301 | Rejected status code: 301 Moved Permanently: Redirects may have been limited by "max-redirects".
     [404] https://mock.httpstatus.io/404 | Rejected status code: 404 Not Found
     
Hint: You can configure accepted response codes with the "accept" option".

We could introduce a Hint struct that collects all of those hints (GitHub token, accept codes, redirects detected).

Originally posted by @mre in #2012 (comment)

Closes #2178

@thomas-zahner thomas-zahner changed the title Draft idea User hints Feb 2, 2026
@thomas-zahner thomas-zahner force-pushed the user-hints branch 3 times, most recently from 0fb03e7 to 977851b Compare February 6, 2026 17:56
Comment thread lychee-bin/src/formatters/hints.rs Outdated
Comment thread lychee-bin/src/formatters/hints.rs Outdated
Comment thread lychee-bin/src/formatters/hints.rs Outdated
Comment thread lychee-lib/src/types/error.rs Outdated
Comment thread lychee-bin/src/hints.rs Outdated
@thomas-zahner

thomas-zahner commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

@mre Thank you for your ideas. Initially I was thinking more of a fully functional approach were we wouldn't need to store state. But your idea also works.

Currently user hints is limited to lychee-bin which makes sense and keeps things simple. But this might also be limiting as there is no way to "trigger" a user hint in lychee-lib. For example with reporting bot protection as mentioned in #2117 this might need to be updated.

Then I was also considering a possibility to hide these hints. Some users might not want to see them or maybe there are scenarios where we shouldn't display them? I was considering:

  • Not showing hints in uncolored terminals
  • Using env variables e.g. NO_HINTS
  • Adding a flag e.g. --no-hints

Edit: ah maybe there's no need to any of this if instead we just use the logging level, so that they can be hidden with -q (see 78af898)

@thomas-zahner thomas-zahner marked this pull request as ready for review April 22, 2026 13:24

@mre mre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I quite like it! Good work. The only remaining comment is optional.

Comment thread lychee-bin/src/hints.rs Outdated
@mre

mre commented Apr 22, 2026

Copy link
Copy Markdown
Member

Edit: ah maybe there's no need to any of this if instead we just use the logging level, so that they can be hidden with -q (see 78af898)

Yeah, that would be great. In general, I'd wait until someone asks for it; but that might just be a "me" thing, haha.

The functional approach also makes sense. While reading your comment, I thought about having a global registry of sorts, similar to how logging gets set up once at the beginning of a binary and then is configured for the rest of the runtime. Maybe you thought of something similar. I haven't looked into it, but I'm guessing the magic would be in a global constant and a function call which reads/writes from/into that.

TBH, I think the current implementation works well and what I like about it is that it's definitely an improvement and still simple enough to understand without obstructing the business logic. The fact that it works on stats is a really nice touch and that's what makes it so self-contained right now.

So I'd have no objections if we merged this.

@thomas-zahner

Copy link
Copy Markdown
Member Author

I've made some small adjustments, feel free to take another look.

Yeah, that would be great. In general, I'd wait until someone asks for it; but that might just be a "me" thing, haha.

I like this approach. But I was already imagining the user asking for a way to hide the hints :)

The functional approach also makes sense.

Agree in the current state it would maybe be even easier. But as soon as we need to have additional ways to add hints (e.g. #2117) the current state is probably necessary.

@mre mre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks really good. Ready to merge from my side.

mre and others added 6 commits April 28, 2026 11:33
The exclusive '..' range syntax follows Rust semantics and excludes
the upper bound, which is a common source of confusion
(e.g. '301..302' only accepts 301, not 302).
Emit a warning to help users notice the mismatch.
@thomas-zahner

thomas-zahner commented Apr 28, 2026

Copy link
Copy Markdown
Member Author

@mre Last updates:

  • I've now moved hints to lychee-lib. This is necessary for us to also collect hints in lychee-lib, as is now done with the accept hint.
  • I've added hint! for more convenience. This feels quite natural as it complements info!, warn!, etc. But it's not exactly the same as it doesn't immediately write something. The hints are only optionally (depending on verbosity) written before program termination.

Comment thread lychee-bin/src/hints.rs
.and_then(|b| b.uri.domain());

if default_host_config && let Some(domain) = first_rate_limited_domain {
hint!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The little exclamation marks make this looks so pretty. 😊

@mre mre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love it.

@thomas-zahner thomas-zahner merged commit 76c5fb2 into lycheeverse:master Apr 29, 2026
8 checks passed
@mre mre mentioned this pull request Apr 29, 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.

Range syntax for accepted status codes not working

2 participants