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

refactor(CLI): Replace warnings with modern counterparts #10080

Merged
merged 3 commits into from Oct 15, 2021

Conversation

pgrzesik
Copy link
Contributor

Addresses: #9860

@@ -133,7 +133,10 @@ class PluginManager {

// don't load plugins twice
if (this.plugins.some((plugin) => plugin instanceof Plugin)) {
this.serverless.cli.log(`WARNING: duplicate plugin ${Plugin.name} was not loaded\n`);
legacy.log(`WARNING: duplicate plugin ${Plugin.name} was not loaded\n`);
log.warning(
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 in my opinion should also stay as a warning - we can succesfully continue with that configuration so it makes no sense to convert it to error, but on the other hand we should let people know that they have duplicated plugins definitions. I've adjusted the copy a little bit as well

Copy link
Contributor

Choose a reason for hiding this comment

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

(in v3) why not making it an error? I don't see a reason to continue the execution here?

Is there a scenario where this bad configuration is "normal"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, this is just a slight configuration issue where someone by mistake specified the plugin more than once - I don't think it should be a hard error as we can move forward with execution and just warn the user about that fact. I guess we could error out but it seemed a bit too strict for me

Copy link
Contributor

Choose a reason for hiding this comment

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

Crashing feels justified if there's a significant risk of following with something not intended by the user, or if simply there's no way to follow with the proposed configuration.

This configuration error feels like an unintended omission that's safe to continue with.

Copy link
Contributor

Choose a reason for hiding this comment

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

Warnings are confusing by nature: something's wrong, but not really. The execution is continuing on an unclear state (from the user POV, not necessarily the technical POV).

Errors are simple: either it's good, either it isn't.

Accomodating errors into warnings makes sense if we ease the life of a major slice of the userbase (e.g. when introducing config validation: the existing errors are just too much, it's too much of an inconvenience to catch up for the whole userbase).

But we should avoid warnings as much as possible:

  • the are confusing
  • they add noise to the output

Here it's a clear case of "something is wrong". Sure we can continue, but that doesn't mean we should. The impacted userbase is, I'd expect, also very limited.

So if we can avoid making it a warning, is it better:

  • a verbose log?
  • a deprecation?
  • or an error?

Sounds to me like error is the best fit (but could be verbose log too?)

Copy link
Contributor

Choose a reason for hiding this comment

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

@mnapoli and why exactly it's harmful to have it covered with deprecation warning instead of regular warning?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mnapoli we'd love to merge it. Still it'll be great first to clarify the logical reason behind introducing breaking change without deprecation.

I don't understand the reason, can you explain what logic drives your decision in this matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

You've asked me to confirm (which I did), and then to double confirm (which I did again) ;) and I explained the reasons just above:

from the information we have (should be extremely rare, users should already see an explicit warning on every command, and we have no knowledge of a valid use case for this) I think it's reasonable

I don't think we should block this PR because we are not introducing any BC break in this PR.

If you want we can discuss it at the meeting in a couple of hours?

Sounds good?

Copy link
Contributor

Choose a reason for hiding this comment

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

from the information we have (should be extremely rare, users should already see an explicit warning on every command, and we have no knowledge of a valid use case for this) I think it's reasonable

It translates to me to:

It's rare, so it's reasonable to introduce breaking change without deprecation message.

I don't understand why fact that it's rare invalidates the need for deprecation messages? What's the rationale behind it?

In other words:

Why do you think it's wrong to configure a deprecation message for extremeley rare case, yet you feel it's important to introduce breaking change for same case?

That's what I'm failing to understand.

This approach technically breaks the contract on our side. So far, no matter if rare or extremely rare breaking changes where accompanied with deprecation warnings and not just warnings. I fail to see a logical reason why this case should be different


Anyway feel free to explain in a meeting

Copy link
Contributor

Choose a reason for hiding this comment

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

Additionally, we don't know how rare this case in reality is. We assume it's very rare.

And configuring deprecation message will give us both:

  • Answer on how rare it is
  • Ensure that in those rare cases, users are properly guided before upgrading to new release.

@codecov
Copy link

codecov bot commented Oct 12, 2021

Codecov Report

Merging #10080 (5f40e36) into master (40f574f) will decrease coverage by 0.14%.
The diff coverage is 46.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10080      +/-   ##
==========================================
- Coverage   85.38%   85.24%   -0.15%     
==========================================
  Files         333      334       +1     
  Lines       13570    13634      +64     
==========================================
+ Hits        11587    11622      +35     
- Misses       1983     2012      +29     
Impacted Files Coverage Δ
lib/cli/commands-schema/resolve-final.js 88.13% <ø> (ø)
lib/utils/eventuallyUpdate.js 26.49% <5.26%> (-1.55%) ⬇️
lib/classes/PluginManager.js 91.31% <18.18%> (-1.87%) ⬇️
lib/plugins/aws/deploy/lib/extendedValidate.js 95.23% <33.33%> (ø)
lib/classes/ConfigSchemaHandler/index.js 90.11% <47.05%> (-1.51%) ⬇️
...b/plugins/aws/package/compile/events/cloudFront.js 96.84% <50.00%> (-2.09%) ⬇️
...ib/plugins/aws/package/lib/generateCoreTemplate.js 95.45% <66.66%> (+0.10%) ⬆️
lib/cli/handle-error.js 84.84% <100.00%> (ø)
lib/plugins/aws/deploy/lib/checkForChanges.js 98.62% <100.00%> (+<0.01%) ⬆️
lib/plugins/aws/deployFunction.js 97.04% <100.00%> (+0.01%) ⬆️
... and 20 more

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 40f574f...5f40e36. Read the comment docs.

lib/classes/PluginManager.js Show resolved Hide resolved
lib/classes/PluginManager.js Outdated Show resolved Hide resolved
lib/cli/commands-schema/resolve-final.js Show resolved Hide resolved
lib/plugins/aws/deploy/lib/checkForChanges.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy/lib/extendedValidate.js Outdated Show resolved Hide resolved
lib/plugins/aws/package/lib/generateCoreTemplate.js Outdated Show resolved Hide resolved
lib/plugins/aws/provider.js Outdated Show resolved Hide resolved
lib/plugins/aws/provider.js Outdated Show resolved Hide resolved
lib/utils/eventuallyUpdate.js Outdated Show resolved Hide resolved
lib/utils/eventuallyUpdate.js Outdated Show resolved Hide resolved
@pgrzesik pgrzesik force-pushed the warnings-modern-logs branch 3 times, most recently from dc231ca to 1da0781 Compare October 12, 2021 11:16
@pgrzesik pgrzesik requested a review from medikoo October 12, 2021 11:28
lib/plugins/aws/invokeLocal/index.js Outdated Show resolved Hide resolved
lib/plugins/aws/lib/checkIfEcrRepositoryExists.js Outdated Show resolved Hide resolved
lib/utils/eventuallyUpdate.js Outdated Show resolved Hide resolved
lib/utils/eventuallyUpdate.js Outdated Show resolved Hide resolved
lib/utils/eventuallyUpdate.js Outdated Show resolved Hide resolved
@pgrzesik pgrzesik force-pushed the warnings-modern-logs branch 2 times, most recently from 24d25b2 to c4207bd Compare October 13, 2021 08:13
@pgrzesik pgrzesik requested a review from mnapoli October 13, 2021 14:34
mnapoli
mnapoli previously approved these changes Oct 13, 2021
Copy link
Contributor

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

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

👍 all good for me, thanks a lot for taking the time on all those comments :p

@pgrzesik pgrzesik requested a review from medikoo October 14, 2021 08:27
@@ -143,7 +145,8 @@ module.exports = {
` configuration in your function "${functionName}".`,
' Serverless will remove this configuration automatically before deployment.',
].join('');
this.serverless.cli.log(warningMessage);
legacy.log(`Warning! ${warningMessage}`);
log.warning(warningMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

This warning message will end to have Warning! prefix. Also it'll be good to put message for modern logs directly into log.warning invocation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great catch, fixed

@pgrzesik pgrzesik force-pushed the warnings-modern-logs branch 3 times, most recently from 6410559 to 4cba05e Compare October 15, 2021 07:44
@pgrzesik pgrzesik requested a review from medikoo October 15, 2021 07:51
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

@pgrzesik looks good. Still please see my comments. I don't think that deprecation warnings should be accompanied with regular warnings (just deprecation warning is good enough I believe, and in such case we should also remove legacy log completely)

Comment on lines 137 to 139
log.warning(
`Duplicate plugin definition found in your configuration. Plugin "${Plugin.name}" will not be loaded more than once.`
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This warning I believe should be gone now (?)

lib/plugins/aws/package/lib/generateCoreTemplate.js Outdated Show resolved Hide resolved
@@ -136,6 +136,7 @@ describe('#generateCoreTemplate()', () => {

return runServerless({
config: {
disabledDeprecations: 'S3_TRANSFER_ACCELERATION_ON_EXISTING_BUCKET',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'll be better to change this test, to one that confirms on deprecation in such scenario.

So Ideally we should leave it to throw and confirm on error code, e.g. we have similar test here:

it('Should report deprecation notice when "enableLocalInstallationFallback" is set', async () =>
expect(
runServerless({
fixture: 'locallyInstalledServerless',
configExt: { enableLocalInstallationFallback: false },
command: 'print',
modulesCacheStub: {},
})
).to.eventually.be.rejected.and.have.property(
'code',
'REJECTED_DEPRECATION_DISABLE_LOCAL_INSTALLATION_FALLBACK_SETTING'
));

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks great 👍

I assume that frameworkVersion case will be taken care with different PR (?)

@pgrzesik
Copy link
Contributor Author

pgrzesik commented Oct 15, 2021

Looks great +1

I assume that frameworkVersion case will be taken care with different PR (?)

I've started a discussion about frameworkVersion because I'm hesitant to turn it into error in all cases - we already report it with an error based on configValidationMode setting and I think we should keep it this way - here's the discussion I started: https://app.asana.com/0/1200011721510709/1201167509383764

What do you think @medikoo ?

@medikoo
Copy link
Contributor

medikoo commented Oct 15, 2021

I've started a discussion about frameworkVersion because I'm hesitant to turn it into error in all cases - we already report it with an error based on configValidationMode setting and I think we should keep it this way - here's the discussion I started: https://app.asana.com/0/1200011721510709/1201167509383764

Good point, I missed that it follows configValidationMode in this case I would keep it the way it works now (with no changes in v3)

@pgrzesik pgrzesik merged commit 04b921a into master Oct 15, 2021
@pgrzesik pgrzesik deleted the warnings-modern-logs branch October 15, 2021 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants