NewRpcError truncates message (256 bytes) and data (15 KiB) with truncateBytes, which slices the string at a byte offset. When the offset falls inside a multi-byte UTF-8 character, the result is invalid UTF-8.
RpcError.toProto() puts that string in a protobuf string field. proto.Marshal rejects invalid UTF-8, so the error response cannot be sent and the caller does not receive the intended error.
Reproduce
msg := "a" + strings.Repeat("é", 200) // 401 bytes
err := lksdk.NewRpcError(lksdk.RpcApplicationError, msg, nil)
// err.Message ends with a partial rune
Marshalling the resulting livekit.RpcError fails with string field contains invalid UTF-8.
Expected
Truncation stops at the last complete character that fits in the limit.
NewRpcErrortruncatesmessage(256 bytes) anddata(15 KiB) withtruncateBytes, which slices the string at a byte offset. When the offset falls inside a multi-byte UTF-8 character, the result is invalid UTF-8.RpcError.toProto()puts that string in a protobufstringfield.proto.Marshalrejects invalid UTF-8, so the error response cannot be sent and the caller does not receive the intended error.Reproduce
Marshalling the resulting
livekit.RpcErrorfails withstring field contains invalid UTF-8.Expected
Truncation stops at the last complete character that fits in the limit.