Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/Tizen.Network.Nfc/Tizen.Network.Nfc/NfcTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Copy link
Copy Markdown
Member Author

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.

Suggested change
taskSource.TrySetException(new InvalidOperationException(((NfcError)result).ToString()));
Log.Error(Globals.LogTag, $"Failed to transceive data, Error - {(NfcError)result}");
try
{
NfcErrorFactory.ThrowNfcException(result);
}
catch (Exception e)
{
taskSource.TrySetException(e);
}

Copy link
Copy Markdown
Member Author

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.

}
_transceiveTaskSource.Remove(requestId);
}
Expand All @@ -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()));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 [AI Review]
🟡 Suggestion: Same as TransceiveCompletedCallback — routing the error through NfcErrorFactory keeps the faulted exception type consistent with the documented contract and restores Log.Error parity.

Suggested change
taskSource.TrySetException(new InvalidOperationException(((NfcError)result).ToString()));
Log.Error(Globals.LogTag, $"Failed to read ndef message, Error - {(NfcError)result}");
try
{
NfcErrorFactory.ThrowNfcException(result);
}
catch (Exception e)
{
taskSource.TrySetException(e);
}

Copy link
Copy Markdown
Member Author

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 read-NDEF error path now logs the failure and routes the native result through NfcErrorFactory.ThrowNfcException, matching TransceiveCompletedCallback.

}
_readNdefTaskSource.Remove(requestId);
}
return ret;
Expand Down
Loading