fix(rclone): guard nil Item in GetFilesSize to avoid panic#328
Merged
Conversation
When the remote does not resolve to a regular file, rclone's Stat
endpoint returns {"item": null}. The file branch of GetFilesSize
dereferenced resp.Item directly and panicked, which surfaced as a
500 with a corrupted body during precheck for cloud sources whose
trailing slash was lost. Treat nil Item as "file not found" so
checkCloud can wrap it into the standard source-not-found error.
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Guard against
resp.Item == nilin the file branch of(*rclone).GetFilesSize, so a missing remote no longer crashesthe request handler.
Background
When precheck runs against a cloud source whose path lacks a
trailing slash,
FileParam.IsFile()reportsisFile=trueandGetFilesSizetakes theStat(..., FilesOnly: true)branch.If the underlying remote actually resolves to a directory (or
does not exist at all), rclone's
operations/statendpointresponds with:
{ "item": null }The previous code dereferenced
resp.Item.Sizeunconditionallyand panicked with
runtime error: invalid memory address or nil pointer dereference. Hertz's recovery middleware kept theprocess alive but the response was already partially written, so
the client saw an HTTP 200 with a corrupted body — symptom on
the wire was a body of just
1instead of a normal JSON envelope.Fix
Treat
resp == nil || resp.Item == nilas "file not found" andreturn a descriptive error.
precheck.checkCloudalready wrapsany
GetFilesSizeerror into the standardSource path to copy does not exist or is not accessible.500 response, so thisaligns the cloud failure surface with the existing sync-source
behaviour.
The same nil-guard pattern is already used in
pkg/drivers/clouds/service.go(the file-stat path), so this isconsistent with prior art in the codebase.
Test plan
sourcemissingthe trailing slash on a path that resolves to a directory
→ expect HTTP 500 + "Source path to copy does not exist or
is not accessible.", no panic in server logs.
source(with or withouttrailing slash) still succeeds end-to-end.
source(trailingslash present) still succeeds end-to-end.
Made with Cursor