mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user