Skip to content

Commit 1aa3de9

Browse files
author
Bas Visscher
committed
Dont catch the origional exceptions in the command executor, the caller should know whats going on
1 parent af39e3b commit 1aa3de9

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

ESPTool/Loaders/ESP32BootLoader/BootLoaderCommandExecutor.cs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,26 @@ public BootLoaderCommandExecutor(Communicator communicator)
1818
/// <exception cref="OperationCanceledException">Thrown if the operation is canceled via the token.</exception>
1919
public async Task<ResponseCommand> ExecuteCommandAsync(RequestCommand requestCommand, CancellationToken token)
2020
{
21-
try
22-
{
23-
_communicator.ClearBuffer();
21+
_communicator.ClearBuffer();
2422

25-
// Convert the RequestCommand to a Frame
26-
Frame requestFrame = RequestToFrame(requestCommand);
23+
// Convert the RequestCommand to a Frame
24+
Frame requestFrame = RequestToFrame(requestCommand);
2725

28-
// Write the frame to the communicator
29-
await _communicator.WriteFrameAsync(requestFrame, token);
26+
// Write the frame to the communicator
27+
await _communicator.WriteFrameAsync(requestFrame, token);
3028

31-
// Read the response frame
32-
Frame responseFrame = await _communicator.ReadFrameAsync(token) ?? throw new Exception("No frame received");
29+
// Read the response frame
30+
Frame responseFrame = await _communicator.ReadFrameAsync(token) ?? throw new Exception("No frame received");
3331

34-
// Convert the response frame back to a ResponseCommand
35-
var response = FrameToResponse(responseFrame);
32+
// Convert the response frame back to a ResponseCommand
33+
var response = FrameToResponse(responseFrame);
3634

37-
// Check
38-
if (response.Command != requestCommand.Command)
39-
{
40-
throw new Exception("Response didnt match");
41-
}
42-
return response;
43-
44-
}
45-
46-
catch (OperationCanceledException)
47-
{
48-
throw new OperationCanceledException("Frame operation was canceled.", token);
49-
}
50-
catch (Exception ex)
35+
// Check
36+
if (response.Command != requestCommand.Command)
5137
{
52-
throw new InvalidOperationException("Failed to send or receive frame.", ex);
38+
throw new Exception("Response didnt match");
5339
}
40+
return response;
5441
}
5542

5643
private static Frame RequestToFrame(RequestCommand command)

ESPTool/Loaders/SoftLoader/SoftLoaderCommandExecutor.cs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,26 @@ public SoftLoaderCommandExecutor(Communicator communicator)
1919
/// <exception cref="OperationCanceledException">Thrown if the operation is canceled via the token.</exception>
2020
public async Task<ResponseCommand> ExecuteCommandAsync(RequestCommand requestCommand, CancellationToken token)
2121
{
22-
try
23-
{
24-
_communicator.ClearBuffer();
25-
26-
// Convert the RequestCommand to a Frame
27-
Frame requestFrame = RequestToFrame(requestCommand);
22+
_communicator.ClearBuffer();
2823

29-
// Write the frame to the communicator
30-
await _communicator.WriteFrameAsync(requestFrame, token);
24+
// Convert the RequestCommand to a Frame
25+
Frame requestFrame = RequestToFrame(requestCommand);
3126

32-
// Read the response frame
33-
Frame responseFrame = await _communicator.ReadFrameAsync(token) ?? throw new Exception("No frame received");
27+
// Write the frame to the communicator
28+
await _communicator.WriteFrameAsync(requestFrame, token);
3429

35-
// Convert the response frame back to a ResponseCommand
36-
var response = FrameToResponse(responseFrame);
37-
38-
// Check
39-
if (response.Command != requestCommand.Command)
40-
{
41-
throw new Exception("Response didnt match");
42-
}
43-
return response;
30+
// Read the response frame
31+
Frame responseFrame = await _communicator.ReadFrameAsync(token) ?? throw new Exception("No frame received");
4432

45-
}
33+
// Convert the response frame back to a ResponseCommand
34+
var response = FrameToResponse(responseFrame);
4635

47-
catch (OperationCanceledException)
36+
// Check
37+
if (response.Command != requestCommand.Command)
4838
{
49-
throw new OperationCanceledException("Frame operation was canceled.", token);
50-
}
51-
catch (Exception ex)
52-
{
53-
throw new InvalidOperationException("Failed to send or receive frame.", ex);
39+
throw new Exception("Response didnt match");
5440
}
41+
return response;
5542
}
5643

5744
private static Frame RequestToFrame(RequestCommand command)

0 commit comments

Comments
 (0)