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

Show a message if cloud functions are duplicated #6963

Merged
merged 4 commits into from
Oct 23, 2020

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Oct 22, 2020

My last PR, this is a little QOL improvement.

Basically, if you create two cloud functions with the same name, the first will be ignored, which is expected behaviour, but can lead to headaches if your main.js is large and you accidentally name a function the same, or you redefine a cloud trigger.

E.g, you create an important validation trigger

Parse.Cloud.beforeSave('TestObject', function (req) {
// important validation
});

And then further on, you think of adding another feature, but forget that you've already written a before save block,

Parse.Cloud.beforeSave('TestObject', function (req) {
// feature two
});

All the validation from the first trigger won't run (which is fine), but it'll be hard to initially know why the code broke.

This just adds a simple console.log on server start, if there are duplicate cloud functions, so developers can understand more what's happening:

Warning: Duplicate cloud functions exist for trigger beforeSave on class TestObject. The first will be ignored.

@ghost
Copy link

ghost commented Oct 22, 2020

Danger run resulted in 1 fail and 1 markdown; to find out more, see the checks page.

Generated by 🚫 dangerJS

@dblythy dblythy changed the title Show a message is cloud functions are duplicated Show a message if cloud functions are duplicated Oct 22, 2020
@codecov
Copy link

codecov bot commented Oct 22, 2020

Codecov Report

Merging #6963 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6963      +/-   ##
==========================================
+ Coverage   93.78%   93.81%   +0.02%     
==========================================
  Files         169      169              
  Lines       12269    12271       +2     
==========================================
+ Hits        11507    11512       +5     
+ Misses        762      759       -3     
Impacted Files Coverage Δ
src/triggers.js 92.53% <100.00%> (+0.04%) ⬆️
src/RestWrite.js 93.82% <0.00%> (ø)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 93.58% <0.00%> (+0.66%) ⬆️

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 c68d055...8887b44. Read the comment docs.

@davimacedo
Copy link
Member

Nice! Thanks for tackling this one. Could you please add a test case?

@dblythy
Copy link
Member Author

dblythy commented Oct 22, 2020

How's that @davimacedo?

src/triggers.js Outdated Show resolved Hide resolved
src/triggers.js Outdated Show resolved Hide resolved
src/triggers.js Outdated Show resolved Hide resolved
src/triggers.js Outdated Show resolved Hide resolved
Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

Good job! Simple and clean.

spec/CloudCode.spec.js Outdated Show resolved Hide resolved
Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

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

LGTM!

@dplewis dplewis merged commit 68a1b30 into parse-community:master Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants