Skip to content

Commit d38472f

Browse files
fix: handle registerPromiseEvent with errors (#2323)
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.
1 parent 90b9708 commit d38472f

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

.eslintrc.js

+9
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ module.exports = {
9999
devDependencies: false,
100100
},
101101
],
102+
'no-restricted-syntax': [
103+
'error',
104+
{
105+
message:
106+
'When `registerPromiseEvent` the `then` need to have a second catch argument',
107+
selector:
108+
'CallExpression[callee.property.name="registerPromiseEvent"] > :first-child[callee.property.name="then"][arguments.length<2]',
109+
},
110+
],
102111
// keep-sorted start block=yes sticky_comments=yes
103112
'@typescript-eslint/array-type': 'warn',
104113
'@typescript-eslint/consistent-generic-constructors': 'warn',

src/bidiMapper/modules/log/LogManager.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,29 @@ export class LogManager {
163163

164164
for (const browsingContext of realm.associatedBrowsingContexts) {
165165
this.#eventManager.registerPromiseEvent(
166-
LogManager.#getExceptionText(params, realm).then((text) => ({
167-
kind: 'success',
168-
value: {
169-
type: 'event',
170-
method: ChromiumBidi.Log.EventNames.LogEntryAdded,
171-
params: {
172-
level: Log.Level.Error,
173-
source: realm.source,
174-
text,
175-
timestamp: Math.round(params.timestamp),
176-
stackTrace: getBidiStackTrace(
177-
params.exceptionDetails.stackTrace
178-
),
179-
type: 'javascript',
166+
LogManager.#getExceptionText(params, realm).then(
167+
(text) => ({
168+
kind: 'success',
169+
value: {
170+
type: 'event',
171+
method: ChromiumBidi.Log.EventNames.LogEntryAdded,
172+
params: {
173+
level: Log.Level.Error,
174+
source: realm.source,
175+
text,
176+
timestamp: Math.round(params.timestamp),
177+
stackTrace: getBidiStackTrace(
178+
params.exceptionDetails.stackTrace
179+
),
180+
type: 'javascript',
181+
},
180182
},
181-
},
182-
})),
183+
}),
184+
(error) => ({
185+
kind: 'error',
186+
error,
187+
})
188+
),
183189
browsingContext.id,
184190
ChromiumBidi.Log.EventNames.LogEntryAdded
185191
);

0 commit comments

Comments
 (0)