[AI Task] [Tizen.Multimedia.MediaPlayer] Fix GetException contract: return instead of throw#7624
[AI Task] [Tizen.Multimedia.MediaPlayer] Fix GetException contract: return instead of throw#7624JoonghyunCho wants to merge 2 commits into
Conversation
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
There was a problem hiding this comment.
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.
| // Notify only when it can't be handled. | ||
| player?.NotifyError((int)errorCode, message); | ||
|
|
||
| throw new InvalidOperationException($"{message} : Unknown error({errorCode})."); |
There was a problem hiding this comment.
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}).");| PlayerErrorCode.NotSupportedAudioCodec => new CodecNotSupportedException(CodecKind.Audio), | ||
| PlayerErrorCode.NotSupportedVideoCodec => new CodecNotSupportedException(CodecKind.Video), |
There was a problem hiding this comment.
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),|
🤖 [AI Review] Reviewed — no findings. Scope checked:
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
|
🤖 [AI Review] |
Summary
Refactors
PlayerErrorCodeExtensionsso thatGetExceptionactually returns the exception (per itsGet*name and itsException-typed signature) instead of throwing in-line. The throw responsibility is centralized inThrowIfFailed, dead code (throw ex;) is removed, and theswitchis condensed to a switch expression.Side fix: corrects the
"Unknow error"typo, which was contained in the now-removeddefault:arm.Changes
src/Tizen.Multimedia.MediaPlayer/Player/PlayerError.csGetException: legacyswitchrewritten as aswitchexpression that returns the mappedException, ornullfor unknown codes.orpatterns group cases that share a target exception type.ThrowIfFailed: now branches on whetherGetExceptionreturned non-null; previously unreachablethrow ex;removed. The "unknown error" fallback (NotifyError+InvalidOperationException) is preserved.{ x.ToString() }→{x}).Mode
Refactoring (no public API signature change; throw types/messages from
ThrowIfFailedpreserved).Verification
dotnet buildofTizen.Multimedia.MediaPlayerand dependencies — 0 errors; only pre-existing repo-wide warnings)internalexception-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)(aprotected staticshim 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 useThrowIfFailed, whose externally-observable behavior is unchanged.Fixes #7592