1
0
mirror of https://github.com/rclone/rclone.git synced 2025-11-23 21:44:49 +02:00
Files
rclone/fs/rc/internal_job_test.go
Nick Craig-Wood 9f75af38e3 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.
2025-11-12 12:22:04 +00:00

39 lines
1.0 KiB
Go

// These tests use the job framework so must be external to the module
package rc_test
import (
"context"
"testing"
"github.com/rclone/rclone/fs/rc"
"github.com/rclone/rclone/fs/rc/jobs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestInternalPanic(t *testing.T) {
ctx := context.Background()
call := rc.Calls.Get("rc/panic")
assert.NotNil(t, call)
in := rc.Params{}
_, out, err := jobs.NewJob(ctx, call.Fn, in)
require.Error(t, err)
assert.ErrorContains(t, err, "arbitrary error on input map[]")
assert.ErrorContains(t, err, "panic received:")
assert.Equal(t, rc.Params{}, out)
}
func TestInternalFatal(t *testing.T) {
ctx := context.Background()
call := rc.Calls.Get("rc/fatal")
assert.NotNil(t, call)
in := rc.Params{}
_, out, err := jobs.NewJob(ctx, call.Fn, in)
require.Error(t, err)
assert.ErrorContains(t, err, "arbitrary error on input map[]")
assert.ErrorContains(t, err, "panic received:")
assert.ErrorContains(t, err, "fatal error:")
assert.Equal(t, rc.Params{}, out)
}