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

Client Accounts.forgotPassword and .verifyEmail pass error in callback #7117

Closed
wants to merge 10 commits into from

Conversation

@laosb
Copy link
Collaborator

@laosb laosb commented May 25, 2016

Issue #5664
Previous PR #5681

This rebased @mishavee 's work. Thank you @mishavee !

@laosb
Copy link
Collaborator Author

@laosb laosb commented May 25, 2016

Failing this:

C: tinytest - passwords - changing passwords : !!!!!!!!! FAIL !!!!!!!!!!!
TypeError: 'undefined' is not a function (evaluating 'callback(new Meteor.Error(400, "Password may not be empty"))')
    at http://localhost:4096/packages/accounts-password.js?hash=862511339ab24b4e1e7ce2ff8c7c7eb124812a89:190
    at http://localhost:4096/packages/local-test_accounts-password.js?hash=cfdd62289298c8f1242c7288d79099ae3ba32d46:405
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:273
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:260
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:237
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:221
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:281
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:260
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:237
    at http://localhost:4096/packages/test-helpers.js?hash=be3b6e8a6205a0152f0b4544ad2896638c07334e:214
    at http://localhost:4096/packages/accounts-password.js?hash=862511339ab24b4e1e7ce2ff8c7c7eb124812a89:215
    at http://localhost:4096/packages/meteor.js?hash=ed600264974381dc7fe10e24064e3d8c8a8eaa14:1105
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:3541
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:3561
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:4677
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:3369
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:2736
    at http://localhost:4096/packages/underscore.js?hash=27b3d669b418de8577518760446467e6ff429b1e:152
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:2737
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:175
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:1160
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:1218
    at http://localhost:4096/packages/ddp-client.js?hash=40a6742de1fccb42fc4e71f0eb5349f2df33c3c8:1365
@laosb
Copy link
Collaborator Author

@laosb laosb commented May 25, 2016

My fault. Rebuilding.

@tmeasday tmeasday changed the title Rebase #5681. Client Accounts.forgotPassword and .verifyEmail pass error in callback May 25, 2016
@laosb
Copy link
Collaborator Author

@laosb laosb commented May 26, 2016

Added in History.md.

@laosb
Copy link
Collaborator Author

@laosb laosb commented May 28, 2016

Pinging @stubailo who reviewed the old PR.

@Menda
Copy link

@Menda Menda commented Jun 3, 2016

Needs rebasing

@laosb
Copy link
Collaborator Author

@laosb laosb commented Jun 3, 2016

Yeah, will do this weekend.

@laosb
Copy link
Collaborator Author

@laosb laosb commented Jun 6, 2016

God slow Internet connection... Will try if I have a good connection.
Receiving objects: 16% (24449/148970), 11.30 MiB | 0 bytes/s

@benjamn
Copy link
Member

@benjamn benjamn commented Jun 7, 2016

I would feel much better about these changes if we continued throwing the exception when there is no callback, rather than silently ignoring it.

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Jun 7, 2016

@laosb to follow up on @benjamn's comment: although this is a well established pattern in this file, it seems really wrong to silently return from these functions when the OPTIONAL callback is not provided and the arguments are incorrect.

Can we please add something to this file like

reportError(error, callback) {
   if (callback) {
     callback(error);
   } else {
     throw error;
   }
}

And replace all the instances of

callback && callback(...);
return;

With

return reportError(callback, ...);
@tmeasday tmeasday self-assigned this Jun 7, 2016
@laosb
Copy link
Collaborator Author

@laosb laosb commented Jun 9, 2016

Oh yeah of course.

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Jun 28, 2016

@laosb were you planning on looking at this?

@laosb
Copy link
Collaborator Author

@laosb laosb commented Jul 1, 2016

@tmeasday Sorry for the delay! Tests running.

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Jul 1, 2016

No problem @laosb !

@laosb
Copy link
Collaborator Author

@laosb laosb commented Jul 1, 2016

My fault of copy&pasting. But the tests shouldn't hang on running when there is a error?
image

@laosb
Copy link
Collaborator Author

@laosb laosb commented Jul 1, 2016

@tmeasday Code fixed but seems that tests are not suitable for this update. Can you give me some hints on modifying tests?

@@ -118,8 +125,7 @@ Accounts.createUser = function (options, callback) {
if (typeof options.password !== 'string')
throw new Error("options.password must be a string");

This comment has been minimized.

@tmeasday

tmeasday Jul 4, 2016
Contributor

Should we use reportError on this line too?

This comment has been minimized.

@tmeasday

tmeasday Jul 4, 2016
Contributor

(Maybe not, we just call check in other places)

@@ -410,6 +410,13 @@ if (Meteor.isClient) (function () {
"email", [
createUserStep,
logoutStep,
// Create user error without callback should not throw error
function (test, expect) {

This comment has been minimized.

@tmeasday

tmeasday Jul 4, 2016
Contributor

Why did you add this new step? I think other tests cover this situation, no? Plus it fails because the password is empty.

@@ -468,6 +475,14 @@ if (Meteor.isClient) (function () {
test.equal(Meteor.user().username, self.username);
}));
},
// change password with bad old password, but no callback so no error
function (test, expect) {
Accounts.changePassword('wrong', 'doesntmatter');

This comment has been minimized.

@tmeasday

tmeasday Jul 4, 2016
Contributor

These should now throw an error right?

},
// forgotPassword called on client with blank email, no callback so no error
function (test, expect) {
Accounts.forgotPassword({ email: this.email });

This comment has been minimized.

@tmeasday

tmeasday Jul 4, 2016
Contributor

Again, this is no longer true.

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Jul 4, 2016

@laosb I made some comments. It looks mostly like we had / you added tests that are now failing because the behaviour is stricter than before. We should just fix those tests to expect errors to be thrown (using test.throws) and I think we'll be good.

@laosb
Copy link
Collaborator Author

@laosb laosb commented Jul 30, 2016

Not sure about what's happening on circle ci. @tmeasday

@abernix
Copy link
Member

@abernix abernix commented Aug 1, 2016

@laosb I would probably rebase this against devel, to start with; a lot has changed in devel since it was rebased last.

@laosb
Copy link
Collaborator Author

@laosb laosb commented Aug 2, 2016

@abernix Yeah I think we should do that. Is it possible that the CircleCI results are related to outdate?

@abernix
Copy link
Member

@abernix abernix commented Aug 2, 2016

That's just the first step to solving CI bugs – especially when it seems that everything is failing in the way it is, you might have been half-way between commits or something when this was originally branched.

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Aug 2, 2016

Looks like there's one failing test left @laosb!

@laosb
Copy link
Collaborator Author

@laosb laosb commented Aug 3, 2016

@tmeasday Yeah, but I don't know how to fix it. The code does throws an error according to the log, but the test suite complains about no error was thrown.

@laosb
Copy link
Collaborator Author

@laosb laosb commented Aug 3, 2016

Oops, my fault of using pull...

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Aug 16, 2016

@laosb I would try rebasing your commits -- something like

git fetch
git checkout your-branch
git reset --hard <last-commit-hash-of-yours>
git rebase <commit-where-you-branched-off-devel> --onto origin/devel
@laosb laosb force-pushed the laosb-rebase-5681 branch from e0e3fd8 to 30c2c46 Aug 17, 2016
@laosb
Copy link
Collaborator Author

@laosb laosb commented Aug 17, 2016

Ok, just rebased!

@laosb
Copy link
Collaborator Author

@laosb laosb commented Aug 18, 2016

Exception in delivering result of invoking 'changePassword': Error: Incorrect password [403]
    at reportError (http://localhost:4096/packages/accounts-password.js?hash=2509f4ba185764fc21922993e746e175ed4a40c3:143)
    at http://localhost:4096/packages/accounts-password.js?hash=2509f4ba185764fc21922993e746e175ed4a40c3:228
    at http://localhost:4096/packages/meteor.js?hash=ed600264974381dc7fe10e24064e3d8c8a8eaa14:1105
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:3557
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:3577
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:4738
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:3385
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:2736
    at http://localhost:4096/packages/underscore.js?hash=27b3d669b418de8577518760446467e6ff429b1e:152
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:2737
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:175
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:1160
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:1218
    at http://localhost:4096/packages/ddp-client.js?hash=2da97e4abeeb8a6d368dcaee62429eca9ff5faca:1365
C: tinytest - passwords - changing passwords : !!!!!!!!! FAIL !!!!!!!!!!!
{"groupPath":["tinytest","passwords"],"test":"changing passwords","events":[{"sequence":110,"type":"fail","details":{"type":"throws","message":"did not throw an error as expected","asyncBlock":4},"cookie":{"name":"passwords - changing passwords","offset":0,"groupPath":["tinytest","passwords"],"shortName":"changing passwords"}}]}

According to the log, it did threw an error but the test suites didn't seen it. @tmeasday can you take a look whether I did something wrong?

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Aug 23, 2016

@laosb the reasons that test is failing is that the error is thrown in a callback (i.e. after the server returns a result of the method call). There's no way on the client to have this thrown as an error you can try {} catch, which is why it ends up getting logged to the console and the test fails.

I think it's OK in this case to not include a test for that behaviour. I've removed the test and I'm merging the PR!

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Aug 23, 2016

Closing in favour of #7695

@tmeasday tmeasday closed this Aug 23, 2016
@laosb laosb deleted the laosb-rebase-5681 branch Aug 26, 2016
tmeasday pushed a commit that referenced this pull request Aug 29, 2016
Move #7117 entry to v.NEXT in History.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants