Skip to content

Commit

Permalink
fix: handle registerPromiseEvent with errors (#2323)
Browse files Browse the repository at this point in the history
Closes #2317.
Closes #2320.

I missed the this in my last PR, but I added a EsLint rule to catch
similar issue in the feature.
It's not 100% robust but it does the job if there is `then` in the
called function.
  • Loading branch information
Lightning00Blade committed Jun 17, 2024
1 parent 90b9708 commit d38472f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ module.exports = {
devDependencies: false,
},
],
'no-restricted-syntax': [
'error',
{
message:
'When `registerPromiseEvent` the `then` need to have a second catch argument',
selector:
'CallExpression[callee.property.name="registerPromiseEvent"] > :first-child[callee.property.name="then"][arguments.length<2]',
},
],
// keep-sorted start block=yes sticky_comments=yes
'@typescript-eslint/array-type': 'warn',
'@typescript-eslint/consistent-generic-constructors': 'warn',
Expand Down
38 changes: 22 additions & 16 deletions src/bidiMapper/modules/log/LogManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,29 @@ export class LogManager {

for (const browsingContext of realm.associatedBrowsingContexts) {
this.#eventManager.registerPromiseEvent(
LogManager.#getExceptionText(params, realm).then((text) => ({
kind: 'success',
value: {
type: 'event',
method: ChromiumBidi.Log.EventNames.LogEntryAdded,
params: {
level: Log.Level.Error,
source: realm.source,
text,
timestamp: Math.round(params.timestamp),
stackTrace: getBidiStackTrace(
params.exceptionDetails.stackTrace
),
type: 'javascript',
LogManager.#getExceptionText(params, realm).then(
(text) => ({
kind: 'success',
value: {
type: 'event',
method: ChromiumBidi.Log.EventNames.LogEntryAdded,
params: {
level: Log.Level.Error,
source: realm.source,
text,
timestamp: Math.round(params.timestamp),
stackTrace: getBidiStackTrace(
params.exceptionDetails.stackTrace
),
type: 'javascript',
},
},
},
})),
}),
(error) => ({
kind: 'error',
error,
})
),
browsingContext.id,
ChromiumBidi.Log.EventNames.LogEntryAdded
);
Expand Down

0 comments on commit d38472f

Please sign in to comment.