kumarabhirup / bulk-mail-cli

Do quick, hassle-free email marketing with this small but very powerful tool! 🔥
https://bulkmail.now.sh
GNU General Public License v3.0
121 stars 24 forks source link

JSON file goes wild: Change settings two times to see a new bracket at end of settings.json file #3

Closed kumarabhirup closed 5 years ago

kumarabhirup commented 5 years ago

Just run this once:

setSetting("username", "Kumar Abhirup")
setSetting("username", "new Kumar Abhirup")

You will see your .config/settings.json JSON file go wild:

{"lang":"cn","username":"Kumar Abhirup"} // Before
{"lang":"cn","username":"new Kumar Abhirup"}} // After

See how that extra bracket breaks everything.

If you made your settings variable in BulkMailCli_settings from var to const, more absurd things are seen. Just like this:

{"lang":"cn","username":"new Kumar Abhirup"}"7890} // WTF???

This needs to be fixed somehow in PR #2

kumarabhirup commented 5 years ago

Yeah, just figured out that the setSetting() function works best only when the value is more than 10 characters. If not, it updates the JSON file wildly.

If the value for a setSetting() is never provided, the same bug occurs again without even throwing us any sort of error.

This is an EPIC BUG.

kumarabhirup commented 5 years ago

UPDATE: This bug is seen when you run setSetting() for more than one time synchronously. I'll try to make it asynchronous. In the meanwhile, I think this bug should let exist till it occurs in the deployment code and I may try my best to not run setSetting() function simultaneously.

kumarabhirup commented 5 years ago

This issue should now be solved.

At the commit ef5f4e7, The setSetting() method returns a Promise. Due to that, the method can now only be called in an async function with an await keyword before.

Look at the example,

var asyncFunction = aync () => {
     await setSetting("lang", "en")
     await setSetting("username", "Kumar Abhirup")
     await setSetting("username", null)
}

👍 💯