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

#2900: Avoid duplicate reporting in menuItemExtension #2901

Merged
merged 15 commits into from
Mar 9, 2022

Conversation

@fregante fregante marked this pull request as ready for review March 8, 2022 03:59
@fregante fregante marked this pull request as draft March 8, 2022 04:01
@fregante fregante marked this pull request as ready for review March 8, 2022 04:03
@fregante
Copy link
Contributor Author

fregante commented Mar 8, 2022

I think these are the only affected lines, at least around these APIs:

  • notifyError
  • notifyErrors
  • notifyResult

They used to map directly to jQuery.notify without reporting the error anywhere. My recent PR added automatic error reporting to all notifications so there might be more elsewhere, but I think I checked those in my last PR (these already used the new API)

@fregante fregante added the bug Something isn't working label Mar 8, 2022
@@ -71,8 +71,7 @@ class BackgroundLogger implements Logger {
}

async error(error: unknown, data: JsonObject): Promise<void> {
console.error("An error occurred: %s", getErrorMessage(error), {
error,
console.error(error, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before

Screen Shot 28

After

Screen Shot 25

void this.runTrigger(element);
}

void this.runTriggersAndNotify(...$element);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this mode, notify was never called

await Promise.allSettled(
$root.toArray().flatMap(async (root) => this.runTrigger(root))
);
await this.runTriggersAndNotify(...$root);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this mode, notify was never called

static notifyErrors(results: Array<PromiseSettledResult<unknown[]>>): void {
const errors = compact(
results.flatMap((x) => (x.status === "fulfilled" ? x.value : [x.reason]))
private async runTriggersAndNotify(...roots: ReaderRoot[]): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was at least partially repeated in 3 places, so I merged it under a single method. However no errors actually ever reach this point due to #2900 (comment)

showNotification({
message,
type: className as NotificationType,
reportError: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This restored the old no-report behavior of notifyResult.

Since this function called by a brick which depends on the jQuery.notify types, I have not fully refactored the function. We should probably look into it at some point. Added to #2865 (comment)

@twschiller twschiller self-requested a review March 8, 2022 14:30
@@ -71,8 +71,7 @@ class BackgroundLogger implements Logger {
}

async error(error: unknown, data: JsonObject): Promise<void> {
console.error("An error occurred: %s", getErrorMessage(error), {
error,
console.error(error, {
Copy link
Contributor

Choose a reason for hiding this comment

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

In practice this should be OK (because this should always be an object). But technically this is not safe/correct because you want to avoid user-defined format strings. In the case of console.log, I think the worst they can do is make the message non-sense

Comment on lines 75 to 76
// Avoid user-defined format strings
console.error("%s", error, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This solution is ok for now, why is the user able to throw strings? We should wrap them as soon as possible I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Theoretically the user isn't able to throw strings. However, the type of error is unknown, so from a defensive coding perspective you want to either: 1) update the type to be accurate, or 2) handle the possibilities

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use selectError in that case to ensure we have a real Error (it wraps strings in new Error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm kinda surprised and annoyed that console.log supports this stuff with random strings 😂

@twschiller twschiller enabled auto-merge (squash) March 9, 2022 02:12
@twschiller twschiller self-requested a review March 9, 2022 02:38
@twschiller twschiller merged commit 9de77df into main Mar 9, 2022
@twschiller twschiller deleted the F/bug/avoid-double-reporting branch March 9, 2022 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Menu Item extension point double reporting to Rollbar (and one is at wrong level)
2 participants