fileserver: Improve 404 error detail and context#7777
Open
Jualhosting wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Improve error handling in file server middleware
Overview
This PR improves the error handling inside the
fileservermiddleware, specifically addressing the ambiguity of404 Not Founderrors.Previously, when a file was not found, a directory lacked an index file, or a file was hidden, the
notFoundmethod would return a genericcaddyhttp.Error(http.StatusNotFound, nil)without any context. This made debugging difficult for users trying to figure out exactly why a resource was returning a 404.🛠️ What’s been fixed?
notFoundsignature: The internalnotFoundfunction now accepts anerr errorargument.notFoundinstaticfiles.goandbrowse.gonow pass specific errors to the response instead ofnil.fmt.Errorf("directory without index file or browse enabled")when an index is missing.fmt.Errorf("file is hidden")when a file matches theHidepaths configuration.fs.ErrNotExistfor missing files.💡 Impact
These changes ensure that logs and error responses now contain actionable context when a 404 is triggered, significantly improving the debuggability of the file server without breaking the
PassThrulogic.🤖 AI Disclosure: The logic updates, context propagation, and documentation in this Pull Request were developed with the assistance of AI, carefully reviewed and tested to ensure Caddy's high standards are met.