Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Conversation

@medikoo
Copy link
Contributor

@medikoo medikoo commented Aug 9, 2019

I think plugin should not exit process abruptly. Technically it leaves Framework stopped without any possibility to do cleanup (e.g. send some statistics info).

Additionally Framework implements error reporting in user friendly way, so I believe it's better to just let the error surface, and let Framework pick it.

@medikoo medikoo force-pushed the improve-exit-on-error branch from 3bae69e to bfedea0 Compare August 9, 2019 14:49
@coveralls
Copy link

coveralls commented Aug 9, 2019

Coverage Status

Coverage decreased (-0.009%) to 83.73% when pulling e359795 on medikoo:improve-exit-on-error into 962c619 on serverless:dev.

@medikoo medikoo force-pushed the improve-exit-on-error branch 3 times, most recently from bf23aeb to 03bee2c Compare August 9, 2019 15:00
Copy link
Contributor

@tbarlow12 tbarlow12 left a comment

Choose a reason for hiding this comment

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

Just a couple items to consider, otherwise looks great.

await invokeLoginHook(false, sls);
try {
await invokeLoginHook(false, sls);
throw new Error("Unexpected");
Copy link
Contributor

Choose a reason for hiding this comment

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

This error shouldn't need to be thrown. The invocation of the login hook should throw the 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 is only to ensure that test will fail if for some reason invokeLoginHook wouldn't crash (see that expect at L96 won't be invoked if we do not throw in try clause - and not invoking expect means that we do not confirm on that behavior).

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but I think if that were the case and this error were actually thrown, the expect assertion within the cache would fail because it's the wrong error. Because we're substituting the interactiveLogin function with an anonymous function that throws an error, it should throw every time. If it doesn't, we have other issues

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this test fail if you remove L94?

Copy link
Contributor Author

@medikoo medikoo Aug 13, 2019

Choose a reason for hiding this comment

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

Right, but I think if that were the case and this error were actually thrown, the expect assertion within the cache would fail because it's the wrong error.

Exactly, that's the intention

Because we're substituting the interactiveLogin function with an anonymous function that throws an error, it should throw every time. If it doesn't, we have other issues

Yes, and it's exactly why I configured the test to fail, and not to silently pass if unexpectedly invokeLoginHook doesn't crash

Does this test fail if you remove L94?

It wouldn't fail if invokeLoginHook would unexpectedly resolve with success (and other constraints will be met) - and that would be the test setup error.


Anyway I've improved the test by using more appropriate construct, which also should make the intention (what we're actually testing) clear.

expect(AzureLoginService.servicePrincipalLogin).not.toBeCalled();
expect(sls.cli.log).lastCalledWith(`Error: ${errorMessage}`);
expect(process.exit).toBeCalledWith(0);
expect(sls.cli.log).lastCalledWith(`Error logging into azure`);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use " instead of ` since there is no string formatting required here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@medikoo medikoo force-pushed the improve-exit-on-error branch 2 times, most recently from 97da989 to e359795 Compare August 9, 2019 15:10
@medikoo medikoo requested a review from tbarlow12 August 9, 2019 15:21
@medikoo medikoo force-pushed the improve-exit-on-error branch from e359795 to 0888fdb Compare August 13, 2019 07:28
Copy link
Contributor

@tbarlow12 tbarlow12 left a comment

Choose a reason for hiding this comment

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

LGTM

@medikoo medikoo requested review from mydiemho and wbreza August 16, 2019 14:15
@tbarlow12 tbarlow12 merged commit de798b6 into serverless:dev Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants