-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
The docs for led me to believe that HTTP redirects would result in warnings from the linkcheck
builder, which I could then turn into a non-0 exit status (and therefore CI failures) via --fail-on-warning
.
linkcheck_allowed_redirects
A dictionary that maps a pattern of the source URI to a pattern of the canonical URI
The linkcheck builder will emit a warning when it finds redirected links that don’t meet the rules above.
It can be useful to detect unexpected redirects when using the fail-on-warnings mode.
(my emphasis)
ref: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-linkcheck_allowed_redirects
I found that if linkcheck_allowed_redirects
is empty or not specific in conf.py
, HTTP redirects are reported in log output but not emitted as warnings.
As a result, redirects could silently make it through the linkcheck
check. To work around this, I'm defining a placeholder like this to get the behavior "fail on any redirects".
linkcheck_allowed_redirects = {"abc": "def"}
How to Reproduce
With sphinx
8.2.3, installed from conda-forge
, ran the quickstart.
mkdir testproject
cd ./testproject
sphinx-quickstart \
--no-sep \
--project testproject \
--author james \
--release v0.1.0 \
--language en docs
Added a link that's guaranteed to redirect into index.rst
.
echo 'See `this link <https://httpbin.org/redirect/1>`_ for details' >> ./docs/index.rst
(you can test this yourself with curl -i https://httpbin.org/redirect/1
)
Saw linkcheck
report the redirect in logs, but return a 0 exit status.
python -m sphinx -b linkcheck --fail-on-warning ./docs/ ./linkcheck_output
# build succeeded.
echo $?
# 0
Including a screenshot instead of text only because I think that the output color indicates something about the type of log message sphinx
is omitting (a difference I don't understand, sorry).

Added a nonsense linkcheck_allowed_redirects
.
echo 'linkcheck_allowed_redirects = {"abc": "def"}' >> ./docs/conf.py
And tried again. This time, saw the redirect reported as a warning (in red this time), an a non-0 exit status.
python -m sphinx -b linkcheck --fail-on-warning ./docs/ ./linkcheck_output
# build finished with problems, 1 warning (with warnings treated as errors).
echo $?
# 1

Environment Information
output of 'python -m sphinx --bug-report' (click me)
Platform: darwin; (macOS-14.4.1-arm64-arm-64bit)
Python version: 3.12.8 | packaged by conda-forge | (main, Dec 5 2024, 14:19:53) [Clang 18.1.8 ])
Python implementation: CPython
Sphinx version: 8.2.3
Docutils version: 0.21.2
Jinja2 version: 3.1.6
Pygments version: 2.19.1
Sphinx extensions
None
Additional context
I'm reporting this as a "bug" because it seems based on the docs that this is unintentional. But if it is intentional, I'd be happy to submit a PR proposing a clarification to those docs explaining how to achieve "fail on any redirects".
I did look for other relevant issues and didn't find any specifically about this. Linking a few somewhat-related:
- maybe there's relevant information in the issue that (I think) led to the
linkcheck_allowed_redirects
(Link checker should be able to prohibit unknown redirects #6525) - maybe whether this is a warning is related to verbosity? (Publish linkcheck failures at end of test #8791, Implement a configuration variable that controls linkcheck verbosity #10946)
Thanks for your time and consideration.