-
Notifications
You must be signed in to change notification settings - Fork 276
[AI Task] Fault NfcTag transceive/read NDEF tasks on native error and remove double dictionary lookup #7774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -324,13 +324,17 @@ public Task<NfcError> FormatNdefMessageAsync(byte[] keyValue) | |||||||||||||||||||||
| void TransceiveCompletedCallback(int result, IntPtr resultData, int dataSize, IntPtr userData) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| int requestId = (int)userData; | ||||||||||||||||||||||
| if (_transceiveTaskSource.ContainsKey(requestId)) | ||||||||||||||||||||||
| if (_transceiveTaskSource.TryGetValue(requestId, out var taskSource)) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| if (result == (int)NfcError.None) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| byte[] resultBuffer = new byte[dataSize]; | ||||||||||||||||||||||
| Marshal.Copy(resultData, resultBuffer, 0, dataSize); | ||||||||||||||||||||||
| _transceiveTaskSource[requestId].TrySetResult(resultBuffer); | ||||||||||||||||||||||
| taskSource.TrySetResult(resultBuffer); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| taskSource.TrySetException(new InvalidOperationException(((NfcError)result).ToString())); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| _transceiveTaskSource.Remove(requestId); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -351,14 +355,18 @@ bool ReadNdefCallback(int result, IntPtr ndefMessage, IntPtr userData) | |||||||||||||||||||||
| { | ||||||||||||||||||||||
| bool ret = false; | ||||||||||||||||||||||
| int requestId = (int)userData; | ||||||||||||||||||||||
| if (_readNdefTaskSource.ContainsKey(requestId)) | ||||||||||||||||||||||
| if (_readNdefTaskSource.TryGetValue(requestId, out var taskSource)) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| if (result == (int)NfcError.None) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| var ndefMsg = new NfcNdefMessage(ndefMessage); | ||||||||||||||||||||||
| _readNdefTaskSource[requestId].TrySetResult(ndefMsg); | ||||||||||||||||||||||
| taskSource.TrySetResult(ndefMsg); | ||||||||||||||||||||||
| ret = true; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| taskSource.TrySetException(new InvalidOperationException(((NfcError)result).ToString())); | ||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [AI Review]
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 [AI Review] |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| _readNdefTaskSource.Remove(requestId); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 [AI Review]
🟡 Suggestion: Faulting with a hardcoded InvalidOperationException bypasses the NfcErrorFactory mapping used by every synchronous error path in this file (NotSupportedError → NotSupportedException, InvalidParameterError → ArgumentException, both documented on TransceiveAsync), and drops the Log.Error parity of the other error branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 [AI Review]
Addressed in efeb1a1 — the transceive error path now logs the failure and routes the native result through NfcErrorFactory.ThrowNfcException, so the faulted exception type matches the documented contract.