rc: make sure fatal errors don't crash rclone - fixes #8955

Before this change, if any code called fs.Fatal(f) then it would stop
rclone as designed. However this is not appropriate when using the RC
API - we want the error returned to the user.

This change turns the fs.Fatal(f) call into a panic which is caught by
the RC API handler and returned to the user as a 500 error.
This commit is contained in:
Nick Craig-Wood
2025-11-10 13:37:28 +00:00
parent b5e4d39b05
commit 9f75af38e3
3 changed files with 105 additions and 0 deletions

View File

@@ -64,6 +64,39 @@ func rcError(ctx context.Context, in Params) (out Params, err error) {
return nil, fmt.Errorf("arbitrary error on input %+v", in)
}
func init() {
Add(Call{
Path: "rc/panic",
Fn: rcPanic,
Title: "This returns an error by panicing",
Help: `
This returns an error with the input as part of its error string.
Useful for testing error handling.`,
})
}
// Return an error regardless
func rcPanic(ctx context.Context, in Params) (out Params, err error) {
panic(fmt.Sprintf("arbitrary error on input %+v", in))
}
func init() {
Add(Call{
Path: "rc/fatal",
Fn: rcFatal,
Title: "This returns an fatal error",
Help: `
This returns an error with the input as part of its error string.
Useful for testing error handling.`,
})
}
// Return an error regardless
func rcFatal(ctx context.Context, in Params) (out Params, err error) {
fs.Fatalf(nil, "arbitrary error on input %+v", in)
return nil, nil
}
func init() {
Add(Call{
Path: "rc/list",