Skip to content

[AI Task] [Tizen.Network.Connection] Stop swallowing native exceptions in event accessors#7625

Open
JoonghyunCho wants to merge 2 commits into
mainfrom
ai-task/issue-7593
Open

[AI Task] [Tizen.Network.Connection] Stop swallowing native exceptions in event accessors#7625
JoonghyunCho wants to merge 2 commits into
mainfrom
ai-task/issue-7593

Conversation

@JoonghyunCho

Copy link
Copy Markdown
Member

Summary

Removes the broad catch (Exception) swallow blocks in the four internal event accessors of ConnectionInternalManager, so that native registration / deregistration failures propagate to callers instead of producing a silent log-only failure.

Changes

  • src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs
    • ConnectionTypeChanged (add / remove): drop try/catch wrapping ConnectionTypeChangedStart() / ConnectionTypeChangedStop().
    • IPAddressChanged (add / remove): drop try/catch wrapping IPAddressChangedStart() / IPAddressChangedStop().
    • EthernetCableStateChanged (add / remove): drop try/catch wrapping EthernetCableStateChangedStart() / EthernetCableStateChangedStop().
    • ProxyAddressChanged (add / remove): drop try/catch wrapping ProxyAddressChangedStart() / ProxyAddressChangedStop().

Total: 8 try/catch blocks removed (~75% reduction in lines for those accessors). Log.Error already exists inside the *Start / *Stop helpers themselves, so diagnostics are preserved. The exception type and message thrown by ConnectionErrorFactory.ThrowConnectionException are unchanged.

Mode

Refactoring (Option A from the issue: propagate exceptions). No public API signatures change. Behaviorally, ConnectionTypeChanged and EthernetCableStateChanged previously swallowed native registration failures (silent failure path); the change surfaces those failures to callers — this is the intended bug-visibility fix.

Verification

  • Build: passed (dotnet build src/Tizen.Network.Connection/Tizen.Network.Connection.csproj — 0 errors, 0 warnings)
  • Tests: N/A (no unit-test project covers this internal manager)
  • Benchmark: skipped — change is on the event registration code path, not a hot path; runtime impact is not the goal of the issue (flagged as code-quality / latent-bug). On-device benchmark also requires sdb device access, which is not available in this environment.

API compatibility note

ConnectionInternalManager is an internal sealed singleton, but its events are surfaced by Tizen.Network.Connection.Connection to user code. Callers of += handler on the corresponding public events may now observe exceptions (e.g., NotSupportedException, InvalidOperationException) where they previously saw a silent log + no registration. This is a behavioral change and intentional — see the issue for rationale. Migration / release-note coverage recommended.

Fixes #7593

Each of the four internal events (ConnectionTypeChanged, IPAddressChanged,
EthernetCableStateChanged, ProxyAddressChanged) wrapped its native-callback
registration / deregistration in a broad catch (Exception) that logged and
returned. For ConnectionTypeChanged and EthernetCableStateChanged the *Start
methods actually throw via ConnectionErrorFactory.ThrowConnectionException,
so registration could silently fail while the caller observed `+= handler`
as having succeeded.

Remove the eight try/catch blocks so native errors propagate to the caller.
The Log.Error inside *Start / *Stop is preserved, and the exception type
and message remain whatever ConnectionErrorFactory already produced.

Fixes #7593
@JoonghyunCho JoonghyunCho requested a review from chleun-moon as a code owner May 10, 2026 11:08
@github-actions github-actions Bot added the API14 Platform : Tizen 11.0 / TFM: net8.0-tizen11.0 label May 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request removes several try-catch blocks within event accessors in ConnectionInternalManager.cs to facilitate exception propagation during event registration and deregistration. The review feedback points out that the underlying helper methods for IPAddressChanged and ProxyAddressChanged still need to be updated to throw exceptions on native failures, as they currently only log errors, which prevents the intended propagation from occurring for those specific events.

Log.Error(Globals.LogTag, $"Exception on adding IPAddressChanged\n{e.ToString()}");
return;
}
IPAddressChangedStart();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While removing the try-catch block here is correct to allow exception propagation, the underlying IPAddressChangedStart() method (lines 272-294) and its counterpart IPAddressChangedStop() (lines 296-304) do not currently call ConnectionErrorFactory.ThrowConnectionException(ret) on failure. To fully achieve the goal of propagating native failures to callers, these helper methods should be updated to throw exceptions when the native registration/deregistration fails, maintaining consistency with ConnectionTypeChangedStart and EthernetCableStateChangedStart.

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 6dd2831. IPAddressChangedStart and IPAddressChangedStop now call ConnectionErrorFactory.ThrowConnectionException(ret) on failure.

Log.Error(Globals.LogTag, $"Exception on adding ProxyAddressChanged\n{e.ToString()}");
return;
}
ProxyAddressChangedStart();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the IPAddressChanged event, the ProxyAddressChangedStart() (lines 332-354) and ProxyAddressChangedStop() (lines 356-364) methods currently only log errors without throwing exceptions. Removing the try-catch block in this accessor won't result in exception propagation for native failures until these helper methods are updated to call ConnectionErrorFactory.ThrowConnectionException(ret).

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 6dd2831. ProxyAddressChangedStart and ProxyAddressChangedStop now call ConnectionErrorFactory.ThrowConnectionException(ret) on failure.

@JoonghyunCho

Copy link
Copy Markdown
Member Author

🤖 [AI Review]

Reviewed — no findings.

Scope checked:

  • 8 try/catch removals across 4 event accessor pairs (ConnectionTypeChanged, EthernetCableStateChanged, IPAddressChanged, ProxyAddressChanged) — symmetric add/remove handling preserved.
  • On the add path, the prior return; (skip subscription on error) is equivalent to throwing before _X += value; runs — net effect on internal state matches.
  • On the remove path, _X -= value; runs before *Stop() so user-handler removal still completes if *Stop() throws — backing field correctness preserved.
  • *Start/*Stop helpers retain their own Log.Error + ConnectionErrorFactory.ThrowConnectionException(ret) (verified at HEAD), so diagnostics are not lost.
  • No public API signatures changed (ConnectionInternalManager is internal sealed); behavioral surface change to Tizen.Network.Connection.Connection callers is intentional per the linked issue.
  • Pre-existing finalizer path (UnregisterEvents() called from ~ConnectionInternalManager) is not touched and not made worse by this PR.

No 🔴 critical issues, no 🟡 suggestions to flag.


Automated review — final merge decision rests with human reviewers.

Throw ConnectionException when registering or unregistering the
IPAddressChanged and ProxyAddressChanged native callbacks fails, so the
event accessors actually surface native failures to callers in line
with the ConnectionTypeChanged and EthernetCableStateChanged helpers.

Applied-Human-Comments: 3214748998,3214749000
@JoonghyunCho

Copy link
Copy Markdown
Member Author

🤖 [AI Review]
Addressed review feedback in commit 6dd2831. Both IPAddressChangedStart/Stop and ProxyAddressChangedStart/Stop now call ConnectionErrorFactory.ThrowConnectionException(ret) on native failure, so removing the try-catch blocks in the event accessors actually propagates errors as intended.

@github-actions github-actions Bot added the API15 label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-task API14 Platform : Tizen 11.0 / TFM: net8.0-tizen11.0 API15

Projects

None yet

1 participant