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

fix(App): Can't catch async errors from singleAuthorization. #837

Closed
wants to merge 5 commits into from

Conversation

Awalgawe
Copy link

Summary

In singleAuthorization, errors from client.auth.test can't be catched.

Requirements (place an x in each [ ])

@gitwave gitwave bot added the untriaged label Mar 18, 2021
@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #837 (18d079c) into main (78e605b) will increase coverage by 0.11%.
The diff coverage is 66.66%.

❗ Current head 18d079c differs from pull request most recent head bb5eac8. Consider uploading reports for the commit bb5eac8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #837      +/-   ##
==========================================
+ Coverage   66.05%   66.16%   +0.11%     
==========================================
  Files          13       13              
  Lines        1193     1200       +7     
  Branches      351      354       +3     
==========================================
+ Hits          788      794       +6     
- Misses        336      338       +2     
+ Partials       69       68       -1     
Impacted Files Coverage Δ
src/App.ts 82.76% <66.66%> (-0.23%) ⬇️
src/receivers/HTTPReceiver.ts 17.75% <0.00%> (+0.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78e605b...bb5eac8. Read the comment docs.

@mwbrooks mwbrooks added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch and removed untriaged labels Mar 18, 2021
@stevengill
Copy link
Member

Hey @Awalgawe,

Thanks for sending the PR! Could you provide a reproduction usecase for the issue?

@Awalgawe
Copy link
Author

Hi @stevengill It arrives when you use a bot token & accidently delete your bot ! ^^'

@Awalgawe
Copy link
Author

we had something like:

try {
  new App({
    token: 'myToken',
    signingSecret: 'MySecret',
  });
} catch (error) {
  // nop 
}

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

I will check the behavior later but can you share error details illustrating the behavior changes and/or write some tests verifying if it works as expected?

src/App.ts Outdated Show resolved Hide resolved
@mwbrooks mwbrooks added the needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info label Mar 18, 2021
src/App.ts Outdated Show resolved Hide resolved
@seratch seratch added this to the 3.4.0 milestone Mar 23, 2021
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

The test cases you've added do not fail with the current implementation.

src/App.spec.ts Outdated Show resolved Hide resolved
@seratch seratch removed this from the 3.4.0 milestone Mar 24, 2021
@seratch
Copy link
Member

seratch commented Mar 24, 2021

@Awalgawe Before discussing the details of your solution, your test code does not fail even with the current implementation. The added tests seem to be unrelated with the following situation you've mentioned:

try {
  new App({
    token: 'myToken',
    signingSecret: 'MySecret',
  });
} catch (error) {
  // nop 
}

Your test code is trying to verify some patterns with App#processEvent method. For the exceptions in the method execution, you can use app.error listeners. I'm thinking that the changes in this PR may not be necessary for your use case.

@Awalgawe
Copy link
Author

@seratch Before my fix, the async error was throwed from the sync context of the App constructor: the previous version of the code create a promise in singleAuthorization but the await was declared in the App.authorize (which is the return value of the singleAuthorization in my case). The unhandled error come from that the fact that the promise can be rejected before being awaited. I made the promise creation lazy to handle this problem. With this fix, the promise is created (and the client.auth.test sent) only when the App.authorize is awaited. So, to test the client.auth.test failure, I need to test a function using App.authorize. This is why I add a test on App.processEvent to catch the App.authorize failure, which is the client.auth.test.

@Awalgawe Awalgawe requested a review from seratch March 24, 2021 16:49
@seratch
Copy link
Member

seratch commented Mar 24, 2021

@Awalgawe Thanks for sharing more details!

At this moment, early failure of auth.test in App constructor (if the given token is not valid) is an intended behavior. Thus, if you are thinking to change the timing of the first auth.test API call to the first event processing, I call it a breaking change. We are unable to merge the change as we have been saying that App initialization verifies the token if you pass it.

Just for reference, We are planning to add a flag to customize the timing of first API call. #718. We have been receiving requests like "I don't want to have the auth.test calls in App constructor.". The new option is for the use cases. If it also works for you and you're interested in working on the ticket instead, I'm happy to work together on it.

@Awalgawe
Copy link
Author

Awalgawe commented Mar 25, 2021

At this moment, early failure of auth.test in App constructor (if the given token is not valid) is an intended behavior.

Oh ok, I didn't expect that after reading the code.

I call it a breaking change

On this part, we have numerous ways to make it not breaking. I'll try something.

@Awalgawe
Copy link
Author

Awalgawe commented Apr 2, 2021

@seratch any comments on new commits ?

@seratch
Copy link
Member

seratch commented Apr 2, 2021

@Awalgawe Oh, you've changed the direction of this pull request and you're trying to implement tokenVerificationEnabled option. That's great! However, as I didn't hear from you, I've implemented the feature at #863 a few days ago. If you have feedback on tokenVerificationEnabled feature, please feel free to leave comments at #863 . I appreciate your time and effort on this pull request.

@seratch
Copy link
Member

seratch commented Aug 11, 2021

As #863 can be a solution for your use case, let us close this pull request now. Thanks again for taking the time to make this pull request!

@seratch seratch closed this Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info semver:patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants