@@ -29,6 +29,9 @@ with Spawn.Processes; use Spawn.Processes;
29
29
30
30
package body LSP.Raw_Clients is
31
31
32
+ Parse_Exception : exception ;
33
+ -- Local exception raised when parsing invalid data
34
+
32
35
New_Line : constant String :=
33
36
(Ada.Characters.Latin_1.CR, Ada.Characters.Latin_1.LF);
34
37
@@ -297,7 +300,7 @@ package body LSP.Raw_Clients is
297
300
Content_Length := Positive'Value (Buffer (From .. Next - 1 ));
298
301
end ;
299
302
else
300
- raise Constraint_Error with " Unexpected header:" & Buffer;
303
+ raise Parse_Exception with " Unexpected header:" & Buffer;
301
304
end if ;
302
305
303
306
Next := Next + New_Line'Length;
@@ -325,12 +328,24 @@ package body LSP.Raw_Clients is
325
328
Start := Index (Client.Buffer, New_Line & New_Line);
326
329
327
330
if Start /= 0 then
328
- Parse_Headers
329
- (Slice (Client.Buffer, 1 , Start + 1 ),
330
- Client.To_Read);
331
-
332
- Delete
333
- (Client.Buffer, 1 , Start + 2 * New_Line'Length - 1 );
331
+ begin
332
+ Parse_Headers
333
+ (Slice (Client.Buffer, 1 , Start + 1 ),
334
+ Client.To_Read);
335
+ Delete
336
+ (Client.Buffer, 1 , Start + 2 * New_Line'Length - 1 );
337
+ exception
338
+ when E : Parse_Exception =>
339
+ Client.On_Exception (E);
340
+ -- Delete the first line
341
+ Start :=
342
+ Index (Client.Buffer,
343
+ " " & Ada.Characters.Latin_1.LF);
344
+ Delete
345
+ (Client.Buffer, 1 , Start);
346
+ -- Reset start to 0 => we didn't find a header
347
+ Start := 0 ;
348
+ end ;
334
349
end if ;
335
350
end if ;
336
351
0 commit comments