Skip to content

Commit 8e24081

Browse files
committed
Apply Qodo /agentic_review pass 3: wrap the shared open too
The shared-open fallback could itself throw, bypassing the normalized IOException and dropping the captured exclusive-open cause. Wrap it and, on a double failure, chain both causes via AggregateException so neither is lost.
1 parent 60e4fcc commit 8e24081

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/Daqifi.Core/Communication/Transport/HidLibraryPlatform.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,27 @@ public void Open(bool exclusive)
161161

162162
if (opened == null)
163163
{
164-
if (!_device.TryOpen(out var sharedStream) || sharedStream == null)
164+
// The shared open can also throw (not just return false); catch it so a throwing shared
165+
// fallback still routes through our normalized IOException and never drops the exclusive cause.
166+
HidStream? sharedStream = null;
167+
Exception? sharedOpenError = null;
168+
try
169+
{
170+
_device.TryOpen(out sharedStream);
171+
}
172+
catch (Exception ex)
173+
{
174+
sharedOpenError = ex;
175+
}
176+
177+
if (sharedStream == null)
165178
{
166-
// Chain the exclusive-open failure (if any) so a double failure preserves the root cause.
167-
throw new IOException("Failed to open HID device.", exclusiveOpenError);
179+
// Both opens failed — preserve whatever cause(s) we have. When both threw, chain both via
180+
// an AggregateException so neither root cause is lost for diagnosis.
181+
var cause = exclusiveOpenError != null && sharedOpenError != null
182+
? new AggregateException(exclusiveOpenError, sharedOpenError)
183+
: sharedOpenError ?? exclusiveOpenError;
184+
throw new IOException("Failed to open HID device.", cause);
168185
}
169186

170187
opened = sharedStream;

0 commit comments

Comments
 (0)