Skip to content
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

Playa 8756 - iOS add callTryCatchWrapper function on JSValue #270

Merged
merged 13 commits into from
Jan 25, 2024
Merged

Conversation

nancywu1
Copy link
Contributor

@nancywu1 nancywu1 commented Jan 18, 2024

for functions not called as a part of a player process like "transition", errors are ignored

tryCatch calls the function inside a try catch to catch the error and return it to allow the callee to determine what they want to do with the error

Change Type (required)

Indicate the type of change your pull request is:

  • patch

  • minor

  • major

    Release Notes

    iOSPlayer to PlayerUI Migration Guide

This guide contains the breaking changes between iOSPlayer and PlayerUI

FlowController Transition

FlowControllers transition function can throw errors in Core Player, however it's not called as a part of a player process so these errors were ignored on iOS.
The change makes the transition function a throwing function. Any existing calls to this now require the try keyword

Before

public func transition(with action: String) {
         value.invokeMethod("transition", withArguments: [action])

After

public func transition(with action: String) throws {
         try self.value.objectForKeyedSubscript("transition").tryCatch(args: [action])

Error is returned from the tryCatch function if it exists

Usage After

(player.state as? InProgressState)?.controllers?.flow.transition(with: "NEXT")

Usage Before

do {
  try (player.state as? InProgressState)?.controllers?.flow.transition(with: "NEXT")
} catch let error {
   // error handling
   // For example: call fail on InProgressState to get ErrorState for flow to end
}

Version

Published prerelease version: 0.6.0-next.2

Changelog

🚀 Enhancement

🐛 Bug Fix

📝 Documentation

Authors: 9

let isError = self.errorCheckWrapper?.call(withArguments: [result as Any])

if isError?.toBool() == true {
throw JSValueError.thrownFromJS
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we include error information about the underlying JS Error?

"""
(fn, args) => {
try {
console.log(args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(args)

console.log(args)
return fn(...args)
} catch(e) {
console.log(e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(e)

return fn(...args)
} catch(e) {
console.log(e)
if (e instanceof Error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should always be true, so its probably not needed

- args: List of arguments taken by the function
*/
public func callTryCatchWrapper(args: Any...) throws {
let result = self.tryCatchWrapper?.call(withArguments: [self, args])
Copy link
Contributor

Choose a reason for hiding this comment

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

Since tryCatchWrapper is a computed property, that means it evals that snippet every time we call this

does JavascriptCore clean it up automatically correctly? or should will we need to handle something?

- parameters:
- args: List of arguments taken by the function
*/
public func callTryCatchWrapper(args: Any...) throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this name is a bit long, can we just call it tryCatch maybe ?

- parameters:
- args: List of arguments taken by the function
*/
public func callTryCatchWrapperWithReturnValue(args: Any...) throws -> JSValue? {
Copy link
Contributor

Choose a reason for hiding this comment

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

you could potentially just use this one and mark it @discardableResult since a Void function in JS would still return undefined technically

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7c26e7b) 81.87% compared to head (09ab468) 82.16%.

❗ Current head 09ab468 differs from pull request most recent head d9470de. Consider uploading reports for the commit d9470de to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #270      +/-   ##
==========================================
+ Coverage   81.87%   82.16%   +0.28%     
==========================================
  Files         134      132       -2     
  Lines        4608     4546      -62     
  Branches     1138     1119      -19     
==========================================
- Hits         3773     3735      -38     
+ Misses        552      534      -18     
+ Partials      283      277       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@hborawski hborawski left a comment

Choose a reason for hiding this comment

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

🚀

@nancywu1 nancywu1 merged commit 58a47fd into main Jan 25, 2024
13 checks passed
@nancywu1 nancywu1 deleted the PLAYA-8756 branch January 25, 2024 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants