carloscuesta / gitmoji-cli

A gitmoji interactive cli tool for using emojis on commits. 💻
https://www.npmjs.com/package/gitmoji-cli
MIT License
4.59k stars 206 forks source link

Config schema violation: `gitmojisUrl` must match format "url" #908

Closed EntePF closed 2 years ago

EntePF commented 2 years ago

Describe the bug

Hi @carloscuesta,

today I updated my gitmoji cask and after that it threw the following error when trying to git commit:

Error: Config schema violation: `gitmojisUrl` must match format "url"
    at Conf._validate (/usr/local/Cellar/gitmoji/6.1.0/libexec/lib/node_modules/gitmoji-cli/node_modules/conf/dist/source/index.js:354:15)
    at get store [as store] (/usr/local/Cellar/gitmoji/6.1.0/libexec/lib/node_modules/gitmoji-cli/node_modules/conf/dist/source/index.js:279:18)
    at new Conf (/usr/local/Cellar/gitmoji/6.1.0/libexec/lib/node_modules/gitmoji-cli/node_modules/conf/dist/source/index.js:131:32)
    at Object.<anonymous> (/usr/local/Cellar/gitmoji/6.1.0/libexec/lib/node_modules/gitmoji-cli/lib/utils/configurationVault/getConfiguration.js:24:29)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at Module.require (node:internal/modules/cjs/loader:1021:19)
    at require (node:internal/modules/cjs/helpers:103:18)

Also gitmoji -g threw this error. I switched to the npm package to install an older version and fix my configuration. But this error showed up in all versions down to 5.0.0 and all the default settings after a clean installation.

Workaround:

With version 5.3.0 I could change the settings using gitmoji -g and ? Set gitmojis api url https://gitmoji.dev/api/gitmojis (instead of leaving it empty) This fixed the issue. After upgrading to 6.1.0 it's still working.

My 2 cents

I guess the variable is set to an invalid value by default and all commands try to load and validate the config and therefore fail. I think there should be a fail-safe to ignore this value if it's invalid or override it with something valid.

Reproduction

Do a clean installation of gitmoji. Or leave all fields empty when gitmoji -g

System Info

System:
    OS: macOS 12.4
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 29.51 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.8.0 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 8.18.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Firefox: 91.12.0
    Firefox Developer Edition: 105.0
    Safari: 15.5

Validations

carloscuesta commented 2 years ago

Hey! Thanks for opening the issue.

I tried reproducing installing a fresh copy of gitmoji, wiping out the stored configuration and the issue doesn't happen.

Screenshot 2022-09-01 at 18 41 24

We have configuration defaults defined for every option in the CLI when no preferences are found as you can see here:

https://github.com/carloscuesta/gitmoji-cli/blob/96c5149b48077338c784922ebe2bf621b01d8eb9/src/utils/configurationVault/getConfiguration.js#L45-L53

https://github.com/carloscuesta/gitmoji-cli/blob/96c5149b48077338c784922ebe2bf621b01d8eb9/src/utils/configurationVault/getConfiguration.js#L7-L12

What is completely possible, is to set the response for the gitmojis api url prompt to an empty " " string which causes the issue that you mentioned 🤔

Even with that I'm still able to execute the gitmoji -g to set the URL again, there's no need to downgrade to previous versions

Screenshot 2022-09-01 at 18 40 43

I will add some validations to the scope prompt so to make users users introduce a valid url when running the config command

EntePF commented 2 years ago

I am also not able to reproduce it anymore. Maybe some bad value (undefined/null/empty) had made its way into my config previously. But your idea to validate the input, so there should never be an invalid url, is great. Thanks for your awesome work.