Skip to content

Commit 6c0fe17

Browse files
committed
Removed the WinGetActionFailedException, because catching, wraping and re-throwing unhandled exceptions causes unneeded performance reduction
1 parent cf0f49e commit 6c0fe17

7 files changed

Lines changed: 266 additions & 1734 deletions

File tree

‎src/WGet.NET/Components/WinGet.cs‎

Lines changed: 36 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,14 @@ public WinGet()
124124
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
125125
/// WinGet is not installed or not found on the system.
126126
/// </exception>
127-
/// <exception cref="WGetNET.Exceptions.WinGetActionFailedException">
128-
/// The current action failed for an unexpected reason.
129-
/// Please see inner exception.
130-
/// </exception>
131127
public string ExportSettings()
132128
{
133129
ThrowIfNotInstalled();
134130

135-
try
136-
{
137-
ProcessResult result =
138-
_processManager.ExecuteWingetProcess(_exportSettingsCmd);
131+
ProcessResult result =
132+
_processManager.ExecuteWingetProcess(_exportSettingsCmd);
139133

140-
return ProcessOutputReader.ExportOutputToString(result);
141-
}
142-
catch (Exception e)
143-
{
144-
throw new WinGetActionFailedException("Exporting sources failed.", _exportSettingsCmd, e);
145-
}
134+
return ProcessOutputReader.ExportOutputToString(result);
146135
}
147136

148137
/// <summary>
@@ -155,25 +144,14 @@ public string ExportSettings()
155144
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
156145
/// WinGet is not installed or not found on the system.
157146
/// </exception>
158-
/// <exception cref="WGetNET.Exceptions.WinGetActionFailedException">
159-
/// The current action failed for an unexpected reason.
160-
/// Please see inner exception.
161-
/// </exception>
162147
public async Task<string> ExportSettingsAsync()
163148
{
164149
ThrowIfNotInstalled();
165150

166-
try
167-
{
168-
ProcessResult result =
169-
await _processManager.ExecuteWingetProcessAsync(_exportSettingsCmd);
151+
ProcessResult result =
152+
await _processManager.ExecuteWingetProcessAsync(_exportSettingsCmd);
170153

171-
return ProcessOutputReader.ExportOutputToString(result);
172-
}
173-
catch (Exception e)
174-
{
175-
throw new WinGetActionFailedException("Exporting sources failed.", _exportSettingsCmd, e);
176-
}
154+
return ProcessOutputReader.ExportOutputToString(result);
177155
}
178156

179157
/// <summary>
@@ -188,10 +166,6 @@ public async Task<string> ExportSettingsAsync()
188166
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
189167
/// WinGet is not installed or not found on the system.
190168
/// </exception>
191-
/// <exception cref="WGetNET.Exceptions.WinGetActionFailedException">
192-
/// The current action failed for an unexpected reason.
193-
/// Please see inner exception.
194-
/// </exception>
195169
/// <exception cref="System.ArgumentNullException">
196170
/// A provided argument is null.
197171
/// </exception>
@@ -225,16 +199,7 @@ public void ExportSettingsToFile(string file)
225199

226200
ThrowIfNotInstalled();
227201

228-
ProcessResult result;
229-
230-
try
231-
{
232-
result = _processManager.ExecuteWingetProcess(_exportSettingsCmd);
233-
}
234-
catch (Exception e)
235-
{
236-
throw new WinGetActionFailedException("Exporting sources failed.", _exportSettingsCmd, e);
237-
}
202+
ProcessResult result = _processManager.ExecuteWingetProcess(_exportSettingsCmd);
238203

239204
FileHandler.ExportOutputToFile(file, result);
240205
}
@@ -251,10 +216,6 @@ public void ExportSettingsToFile(string file)
251216
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
252217
/// WinGet is not installed or not found on the system.
253218
/// </exception>
254-
/// <exception cref="WGetNET.Exceptions.WinGetActionFailedException">
255-
/// The current action failed for an unexpected reason.
256-
/// Please see inner exception.
257-
/// </exception>
258219
/// <exception cref="System.ArgumentNullException">
259220
/// A provided argument is null.
260221
/// </exception>
@@ -288,16 +249,7 @@ public async Task ExportSettingsToFileAsync(string file)
288249

289250
ThrowIfNotInstalled();
290251

291-
ProcessResult result;
292-
293-
try
294-
{
295-
result = await _processManager.ExecuteWingetProcessAsync(_exportSettingsCmd);
296-
}
297-
catch (Exception e)
298-
{
299-
throw new WinGetActionFailedException("Exporting sources failed.", _exportSettingsCmd, e);
300-
}
252+
ProcessResult result = await _processManager.ExecuteWingetProcessAsync(_exportSettingsCmd);
301253

302254
await FileHandler.ExportOutputToFileAsync(file, result);
303255
}
@@ -311,39 +263,28 @@ public async Task ExportSettingsToFileAsync(string file)
311263
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
312264
/// WinGet is not installed or not found on the system.
313265
/// </exception>
314-
/// <exception cref="WGetNET.Exceptions.WinGetActionFailedException">
315-
/// The current action failed for an unexpected reason.
316-
/// Please see inner exception.
317-
/// </exception>
318266
public WinGetInfo GetInfo()
319267
{
320268
ThrowIfNotInstalled();
321269

322-
try
323-
{
324-
ProcessResult result =
325-
_processManager.ExecuteWingetProcess(_infoCmd);
326-
327-
InfoActionVersionId actionVersionId = InfoActionVersionId.VersionRange1;
328-
if (CheckWinGetVersion(new Version(1, 4, 3531), new Version(1, 5, 101)))
329-
{
330-
actionVersionId = InfoActionVersionId.VersionRange2;
331-
}
332-
else if (CheckWinGetVersion(new Version(1, 5, 441), new Version(1, 5, 441)))
333-
{
334-
actionVersionId = InfoActionVersionId.VersionRange3;
335-
}
336-
else if (CheckWinGetVersion(new Version(1, 5, 1081)))
337-
{
338-
actionVersionId = InfoActionVersionId.VersionRange4;
339-
}
270+
ProcessResult result =
271+
_processManager.ExecuteWingetProcess(_infoCmd);
340272

341-
return ProcessOutputReader.ToWingetInfo(result.Output, actionVersionId);
273+
InfoActionVersionId actionVersionId = InfoActionVersionId.VersionRange1;
274+
if (CheckWinGetVersion(new Version(1, 4, 3531), new Version(1, 5, 101)))
275+
{
276+
actionVersionId = InfoActionVersionId.VersionRange2;
277+
}
278+
else if (CheckWinGetVersion(new Version(1, 5, 441), new Version(1, 5, 441)))
279+
{
280+
actionVersionId = InfoActionVersionId.VersionRange3;
342281
}
343-
catch (Exception e)
282+
else if (CheckWinGetVersion(new Version(1, 5, 1081)))
344283
{
345-
throw new WinGetActionFailedException("Getting data failed.", _infoCmd, e);
284+
actionVersionId = InfoActionVersionId.VersionRange4;
346285
}
286+
287+
return ProcessOutputReader.ToWingetInfo(result.Output, actionVersionId);
347288
}
348289

349290
/// <summary>
@@ -356,39 +297,28 @@ public WinGetInfo GetInfo()
356297
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
357298
/// WinGet is not installed or not found on the system.
358299
/// </exception>
359-
/// <exception cref="WGetNET.Exceptions.WinGetActionFailedException">
360-
/// The current action failed for an unexpected reason.
361-
/// Please see inner exception.
362-
/// </exception>
363300
public async Task<WinGetInfo> GetInfoAsync()
364301
{
365302
ThrowIfNotInstalled();
366303

367-
try
368-
{
369-
ProcessResult result =
370-
await _processManager.ExecuteWingetProcessAsync(_infoCmd);
371-
372-
InfoActionVersionId actionVersionId = InfoActionVersionId.VersionRange1;
373-
if (CheckWinGetVersion(new Version(1, 4, 3531), new Version(1, 5, 101)))
374-
{
375-
actionVersionId = InfoActionVersionId.VersionRange2;
376-
}
377-
else if (CheckWinGetVersion(new Version(1, 5, 441), new Version(1, 5, 441)))
378-
{
379-
actionVersionId = InfoActionVersionId.VersionRange3;
380-
}
381-
else if (CheckWinGetVersion(new Version(1, 5, 1081)))
382-
{
383-
actionVersionId = InfoActionVersionId.VersionRange4;
384-
}
304+
ProcessResult result =
305+
await _processManager.ExecuteWingetProcessAsync(_infoCmd);
385306

386-
return ProcessOutputReader.ToWingetInfo(result.Output, actionVersionId);
307+
InfoActionVersionId actionVersionId = InfoActionVersionId.VersionRange1;
308+
if (CheckWinGetVersion(new Version(1, 4, 3531), new Version(1, 5, 101)))
309+
{
310+
actionVersionId = InfoActionVersionId.VersionRange2;
387311
}
388-
catch (Exception e)
312+
else if (CheckWinGetVersion(new Version(1, 5, 441), new Version(1, 5, 441)))
389313
{
390-
throw new WinGetActionFailedException("Getting data failed.", _infoCmd, e);
314+
actionVersionId = InfoActionVersionId.VersionRange3;
391315
}
316+
else if (CheckWinGetVersion(new Version(1, 5, 1081)))
317+
{
318+
actionVersionId = InfoActionVersionId.VersionRange4;
319+
}
320+
321+
return ProcessOutputReader.ToWingetInfo(result.Output, actionVersionId);
392322
}
393323

394324
/// <summary>

0 commit comments

Comments
 (0)