@@ -167,6 +167,49 @@ def output_protocol
167167 end
168168 end
169169
170+ it "returns protocol errors for malformed request arguments" do
171+ handler = double ( "Handler" )
172+ expect ( handler ) . not_to receive ( :sleep )
173+ processor = SpecNamespace ::NonblockingService ::Processor . new ( handler )
174+ input = Thrift ::JsonProtocol . new (
175+ Thrift ::MemoryBufferTransport . new ( '[1,"sleep",1,17,{"1":{"dbl":x}}]' ) ,
176+ )
177+ output_transport = Thrift ::MemoryBufferTransport . new
178+
179+ expect ( processor . process ( input , Thrift ::JsonProtocol . new ( output_transport ) ) ) . to be true
180+
181+ response = Thrift ::JsonProtocol . new ( output_transport )
182+ expect ( response . read_message_begin ) . to eq ( [ "sleep" , Thrift ::MessageTypes ::EXCEPTION , 17 ] )
183+ exception = Thrift ::ApplicationException . new
184+ exception . read ( response )
185+ response . read_message_end
186+
187+ expect ( exception . type ) . to eq ( Thrift ::ApplicationException ::PROTOCOL_ERROR )
188+ expect ( exception . message ) . to eq ( 'Expected numeric value; got ""' )
189+ end
190+
191+ it "keeps protocol exceptions raised by handlers as internal errors" do
192+ handler = double ( "Handler" )
193+ expect ( handler ) . to receive ( :sleep ) . with ( 3.0 ) . and_raise (
194+ Thrift ::ProtocolException . new ( Thrift ::ProtocolException ::INVALID_DATA , "handler failed" ) ,
195+ )
196+ processor = SpecNamespace ::NonblockingService ::Processor . new ( handler )
197+ args = SpecNamespace ::NonblockingService ::Sleep_args . new ( seconds : 3.0 )
198+ input = input_protocol ( "sleep" , Thrift ::MessageTypes ::CALL , 18 , args )
199+ output_transport , output = output_protocol
200+
201+ expect ( processor . process ( input , output ) ) . to be true
202+
203+ response = Thrift ::BinaryProtocol . new ( output_transport )
204+ expect ( response . read_message_begin ) . to eq ( [ "sleep" , Thrift ::MessageTypes ::EXCEPTION , 18 ] )
205+ exception = Thrift ::ApplicationException . new
206+ exception . read ( response )
207+ response . read_message_end
208+
209+ expect ( exception . type ) . to eq ( Thrift ::ApplicationException ::INTERNAL_ERROR )
210+ expect ( exception . message ) . to eq ( "Internal error" )
211+ end
212+
170213 it "should write out a reply when asked" do
171214 expect ( @prot ) . to receive ( :write_message_begin ) . with ( "testMessage" , Thrift ::MessageTypes ::REPLY , 23 ) . ordered
172215 result = double ( "MockResult" )
0 commit comments