From 335990afa5f2ae51f2af9c1ca926ec6b8954b906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Podg=C3=B3rski?= <4056521+kuba--@users.noreply.github.com> Date: Sun, 9 Aug 2026 09:42:24 +0200 Subject: [PATCH] return psrpc.FailedPrecondition for "participant client version does not support moving" error (#4736) --- pkg/rtc/participant.go | 9 +++++++-- pkg/rtc/participant_internal_test.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 8a8f0a768..2d86565f6 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -83,7 +83,7 @@ const ( ) var ( - ErrMoveOldClientVersion = errors.New("participant client version does not support moving") + ErrMoveOldClientVersion = psrpc.NewErrorf(psrpc.FailedPrecondition, "participant client version does not support moving") ) // ------------------------------------------------- @@ -4103,7 +4103,12 @@ func (p *ParticipantImpl) SupportsMoving() error { } if kind := p.Kind(); kind == livekit.ParticipantInfo_EGRESS || kind == livekit.ParticipantInfo_AGENT || p.params.UseOneShotSignallingMode { - return fmt.Errorf("%s participants cannot be moved, one-shot signaling mode: %t", kind.String(), p.params.UseOneShotSignallingMode) + return psrpc.NewErrorf( + psrpc.FailedPrecondition, + "%s participants cannot be moved, one-shot signaling mode: %t", + kind.String(), + p.params.UseOneShotSignallingMode, + ) } return nil diff --git a/pkg/rtc/participant_internal_test.go b/pkg/rtc/participant_internal_test.go index 68c7277e4..33263a360 100644 --- a/pkg/rtc/participant_internal_test.go +++ b/pkg/rtc/participant_internal_test.go @@ -22,6 +22,7 @@ import ( "github.com/pion/webrtc/v4" "github.com/stretchr/testify/require" + "github.com/twitchtv/twirp" "go.uber.org/atomic" "google.golang.org/protobuf/proto" @@ -77,6 +78,26 @@ func TestIsReady(t *testing.T) { } } +func TestSupportsMoving(t *testing.T) { + t.Run("current protocol version", func(t *testing.T) { + p := newParticipantForTestWithOpts("test", &participantOpts{protocolVersion: types.CurrentProtocol}) + require.NoError(t, p.SupportsMoving()) + }) + + // a move rejected because of what the participant is cannot be retried into working, but it is + // still a caller error, so it has to surface as a 4xx rather than a 500 + t.Run("client version that cannot be moved", func(t *testing.T) { + p := newParticipantForTestWithOpts("test", &participantOpts{protocolVersion: 6}) + + err := p.SupportsMoving() + require.ErrorIs(t, err, ErrMoveOldClientVersion) + + var twirpErr twirp.Error + require.ErrorAs(t, err, &twirpErr) + require.Equal(t, twirp.FailedPrecondition, twirpErr.Code()) + }) +} + func TestTrackPublishing(t *testing.T) { t.Run("should send the correct events", func(t *testing.T) { p := newParticipantForTest("test")