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

Bubble up exceptions in JS into .NET #27129

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mattleibow
Copy link
Member

Description of Change

Issues Fixed

Fixes #27097

@Copilot Copilot bot review requested due to automatic review settings January 14, 2025 19:26
@mattleibow mattleibow requested a review from a team as a code owner January 14, 2025 19:26

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 9 changed files in this pull request and generated no comments.

Files not reviewed (4)
  • src/Controls/tests/DeviceTests/Resources/Raw/HybridTestRoot/index.html: Language not supported
  • src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs: Evaluated as low risk
  • src/Controls/tests/DeviceTests/Elements/HybridWebView/HybridWebViewTests.cs: Evaluated as low risk
  • src/Core/src/Handlers/HybridWebView/HybridWebViewTaskManager.cs: Evaluated as low risk
Comments suppressed due to low confidence (2)

src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.cs:115

  • Ensure that the new exception handling logic for '__InvokeJavaScriptFailed' is covered by tests.
case "__InvokeJavaScriptFailed":

src/Core/src/Handlers/HybridWebView/HybridWebViewTask.cs:5

  • [nitpick] The term 'TaskId' is clear, but ensure that all new symbols follow the same clarity and consistency.
internal record struct HybridWebViewTask(string TaskId, TaskCompletionSource<string?> TaskCompletionSource);
@mattleibow mattleibow self-assigned this Jan 14, 2025
@mattleibow mattleibow added the area-controls-hybridwebview HybridWebView control label Jan 14, 2025
@mattleibow mattleibow added this to the .NET 9 SR4 milestone Jan 14, 2025
Comment on lines +71 to +79
if (errorType === 1) { // throw number
throw value;
} else if (errorType === 2) { // throw string
throw `String: ${value}`;
} else if (errorType === 3) { // throw Error
throw new Error(`Generic Error: ${value}`);
} else if (errorType === 4) { // throw runtime Error
undefined.toString();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I think these are the main types of errors in JS?

@@ -91,20 +91,49 @@
}
},

"__InvokeJavaScript": function __InvokeJavaScript(taskId, methodName, args) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These changes are backwards/forwards compatible. Before this PR, an error just never calls back into C#. All the changes are in the new function that catches exceptions and calls back into .NET. If you have the old JS, nothing will change.

Comment on lines -40 to +41
public partial class HybridWebViewHandler : IHybridWebViewHandler, IHybridWebViewTaskManager
public partial class HybridWebViewHandler : IHybridWebViewHandler
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the task manager into a separate service to help with testing ... which I haven't written yet. But also, allows a new handler to work without depending on this internal interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-hybridwebview HybridWebView control
Projects
Status: Ready To Review
Development

Successfully merging this pull request may close these issues.

HybridWebView needs a consistent and usable story for handling JS methods that throw exceptions
1 participant