Skip to content

[AI Task] [Tizen.Multimedia.MediaPlayer] Fix GetException contract: return instead of throw#7624

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

[AI Task] [Tizen.Multimedia.MediaPlayer] Fix GetException contract: return instead of throw#7624
JoonghyunCho wants to merge 2 commits into
mainfrom
ai-task/issue-7592

Conversation

@JoonghyunCho

Copy link
Copy Markdown
Member

Summary

Refactors PlayerErrorCodeExtensions so that GetException actually returns the exception (per its Get* name and its Exception-typed signature) instead of throwing in-line. The throw responsibility is centralized in ThrowIfFailed, dead code (throw ex;) is removed, and the switch is condensed to a switch expression.

Side fix: corrects the "Unknow error" typo, which was contained in the now-removed default: arm.

Changes

  • src/Tizen.Multimedia.MediaPlayer/Player/PlayerError.cs
    • GetException: legacy switch rewritten as a switch expression that returns the mapped Exception, or null for unknown codes. or patterns group cases that share a target exception type.
    • ThrowIfFailed: now branches on whether GetException returned non-null; previously unreachable throw ex; removed. The "unknown error" fallback (NotifyError + InvalidOperationException) is preserved.
    • Format-string interpolations simplified ({ x.ToString() }{x}).

Mode

Refactoring (no public API signature change; throw types/messages from ThrowIfFailed preserved).

Verification

  • Build: passed (dotnet build of Tizen.Multimedia.MediaPlayer and dependencies — 0 errors; only pre-existing repo-wide warnings)
  • Tests: N/A (no unit tests exist for this internal helper in the repo)
  • Benchmark: skipped — refactor target is an internal exception-mapping helper on the error path; runtime impact is not the goal of this issue (the issue itself flags it as code-quality, not perf-critical) and benchmarking is gated on physical sdb device access not available here.

API compatibility note

Player.GetException(int, string) (a protected static shim wrapping the extension) inherits the contract change: it now returns the mapped exception instead of throwing for known codes. This brings runtime behavior in line with the documented signature (Exception GetException(...)); the previous behavior was a latent contract bug. All in-tree call sites use ThrowIfFailed, whose externally-observable behavior is unchanged.

Fixes #7592

GetException is named for value retrieval but currently throws,
violating .NET design guidelines and rendering the trailing
'throw ex;' in ThrowIfFailed unreachable. Convert the body to a
switch expression that returns the mapped Exception (or null for
unknown codes), centralize the throw site in ThrowIfFailed, and
fix a 'Unknow' typo in the previous default-arm log message.

Behavior of ThrowIfFailed is preserved: same exception types and
messages are thrown, with the existing NotifyError + InvalidOperationException
fallback path retained for unknown codes.

Fixes #7592
@JoonghyunCho JoonghyunCho requested a review from hsgwon as a code owner May 10, 2026 11:05
@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 refactors error handling in PlayerError.cs, converting a large switch statement into a more concise switch expression and streamlining the logic in ThrowIfFailed. Feedback suggests restoring the diagnostic logging for unknown error codes that was removed during refactoring and ensuring that CodecNotSupportedException includes the formatted error message for consistency with other exception types.

Comment on lines +71 to +74
// Notify only when it can't be handled.
player?.NotifyError((int)errorCode, message);

throw new InvalidOperationException($"{message} : Unknown error({errorCode}).");

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

The refactoring removed the diagnostic logging for unknown error codes. While the typo was fixed by deletion, losing this log entry makes post-mortem analysis harder when exceptions are swallowed or not fully logged. Additionally, if message is null, the exception message will start with a colon. It is better to preserve the logging (with the typo fixed) and ensure the exception message has a sensible fallback.

            // Notify only when it can't be handled.
            player?.NotifyError((int)errorCode, message);

            Log.Info(PlayerLog.Tag, $"Unknown error: {errorCode}");

            throw new InvalidOperationException($"{(message ?? "Operation failed")} : Unknown error({errorCode}).");

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 c360d57.

Comment on lines +108 to +109
PlayerErrorCode.NotSupportedAudioCodec => new CodecNotSupportedException(CodecKind.Audio),
PlayerErrorCode.NotSupportedVideoCodec => new CodecNotSupportedException(CodecKind.Video),

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

For consistency with all other error cases in this switch expression, CodecNotSupportedException should also include the formatted error message (msg). Currently, these are the only cases that omit the context message and error code, which results in less informative exceptions for codec-related failures.

                PlayerErrorCode.NotSupportedAudioCodec          => new CodecNotSupportedException(CodecKind.Audio, msg),
                PlayerErrorCode.NotSupportedVideoCodec          => new CodecNotSupportedException(CodecKind.Video, msg),

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 c360d57.

@JoonghyunCho

Copy link
Copy Markdown
Member Author

🤖 [AI Review]

Reviewed — no findings.

Scope checked:

  • GetException rewritten as switch expression (15 PlayerErrorCode arms + _ => null) — every arm maps to the same exception type as the prior throw new …(msg) (verified arm-by-arm: DRM codes + 5 invalid-op codes → InvalidOperationException; codec codes → CodecNotSupportedException(CodecKind.*); etc.).
  • ThrowIfFailed control flow inverted (ex != null → throw ex; else NotifyError + InvalidOperationException) — removes the unreachable throw ex; and the duplicate-throw dead path; unknown-code message text and player?.NotifyError(...) side effect preserved.
  • Only external surface is the Player.GetException(int, string) protected static shim — annotated [EditorBrowsable(EditorBrowsableState.Never)] per Player.ErrorHandler.cs:37-39, so the contract-fix (return instead of throw) is acceptable per TizenFX convention.
  • { x.ToString() }{x} interpolation simplification is equivalent (both invoke Enum.ToString via the IFormattable path for enums).
  • TODO comment intent preserved (relocated above the DRM-prefixed or-group; "below" is grammatically consistent).
  • Log.Info("Unknow error: ...") removal in the default arm is a deliberate diagnostic trade-off — ThrowIfFailed still surfaces unknown codes via NotifyError + InvalidOperationException, so the in-tree observable path is unchanged.

No 🔴 critical issues, no 🟡 suggestions to flag.


Automated review — final merge decision rests with human reviewers.

Restore diagnostic log for unknown player error codes with the typo
fixed, guard against null message in the exception text, and pass the
formatted error message into CodecNotSupportedException for parity with
other error cases.

Applied-Human-Comments: 3214746677,3214746678
@github-actions github-actions Bot added the API15 label May 11, 2026
@JoonghyunCho

Copy link
Copy Markdown
Member Author

🤖 [AI Review]
Addressed review feedback in commit c360d57. Restored the diagnostic Log.Info for unknown player error codes with the typo fixed, guarded the InvalidOperationException message against a null message, and passed the formatted error message into CodecNotSupportedException for consistency with the other error cases.

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