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

Better error handling when the configuration file data structure is incorrect #102

Open
jakebolam opened this issue Jan 26, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@jakebolam
Copy link
Contributor

jakebolam commented Jan 26, 2019

Is your feature request related to a problem? Please describe.
When the configuration file datastructure is incorrect,the bot fails in weird and wonderful ways. e.g.

{
    "projectName": "coding_challenge-13",
    "projectOwner": "zeroDevs",
    "repoType": "github",
    "repoHost": "https://github.com",
    "files": [
        "README.md"
    ],
    "imageSize": 100,
    "commit": true,
    "contributors": [
        {
            "login": "The24thDS",
            "name": "David Sima",
            "avatar_url": "https://avatars0.githubusercontent.com/u/26633429?v=4",
            "profile": "https://github.com/The24thDS",
            "contributions": [
                "code",
                "bug",
                "review"
            ]
        },
        {
            "login": "mikeattara",
            "name": "Mike Perry Y Attara",
            "avatar_url": "https://avatars1.githubusercontent.com/u/31483629?v=4",
            "profile": "https://mikeattara.com",
            "contributions": [
                "ideas",
                "code",
                "review",
                "test"
            ]
        },
        {
            "login": "AkinAguda",
            "name": "Akinwunmi Aguda",
            "avatar_url": "https://avatars0.githubusercontent.com/u/39712415?v=4",
            "profile": "https://github.com/AkinAguda",
            "contributions": [
                "bug"
            ]
        },
        {
            "login": "jakebolam",
            "name": "Jake Bolam",
            "avatar_url": "https://avatars2.githubusercontent.com/u/3534236?v=4",
            "profile": "https://jakebolam.com",
            "contributions": [
                "question"
            ]
        },
        {
            "login": "aneagoie",
            "name": "Andrei Neagoie",
            "avatar_url": "https://avatars3.githubusercontent.com/u/10776230?v=4",
            "profile": "https://github.com/aneagoie",
            "contributions": [
                "bug",
                "code",
                "ideas",
                "review"
            ]
        },
        {
            "login": "MattCSmith",
            "name": "Matt Smith",
            "avatar_url": "https://avatars3.githubusercontent.com/u/6190356?v=4",
            "profile": "https://github.com/MattCSmith",
            "contributions": [
                "question",
                "bug",
                "code",
                "ideas",
                "review"
            ]
        },
        {
            "contributions": [
                "ideas"
            ]
        },
      ]
}

Technically valid JSON but the schema is busted.

Describe the solution you'd like
Provide great error messages, so users no whats wrong with the schema.

Even better: Auto fix it!

Additional context
See: https://sentry.io/all-contributors/github-bot/issues/859146506/?query=is%3Aunresolved

Also issues: zeroDevs/FullstackTrends_Challenge-13#182

@Berkmann18
Copy link
Member

Berkmann18 commented Feb 6, 2019

An approach to this would be:

try {
  JSON.parse(config);
} catch (err) {
  // auto-fix and/or log errors if it can't fix it
}

There are some interesting solutions in this SO post (although most are for only fixing quote issues).

https://jsontuneup.com/ might be a helpful example.

In any case, this comes down to the CLI dependency not being able to parse a malformed configuration file. I started looking into that and found a decent library that provides much more informative errors and which I'm currently exploiting to see if I can get an auto-fixer into the mix.

Berkmann18 added a commit to all-contributors/cli that referenced this issue Feb 7, 2019
Added a module that will check JSON files and give a good level of details for errors while
attempting to fix it

re all-contributors/app#102
@jakebolam
Copy link
Contributor Author

This also broke the schema. Specifying invalid contribution types in the JSON. See sentry: https://sentry.io/organizations/all-contributors/issues/957977140/events/50916998062/

@jakebolam jakebolam changed the title Better error handling when the configuration file is malformed. Better error handling when the configuration file data structure is incorrect May 4, 2019
@jakebolam jakebolam pinned this issue May 4, 2019
Berkmann18 added a commit to all-contributors/cli that referenced this issue May 20, 2019
* feat: added a JSON handler/fixer [wip]

Added a module that will check JSON files and give a good level of details for errors while
attempting to fix it

re all-contributors/app#102

* refactor: consolidated the fix handler

Made the fixer a bit more concise and added the fields to allow for an auto-update of the config
file (if it was changed)

* chore(package): use another `jsonlint`

* refactor(config-file): use `json-fixer`

* chore(package): bump `json-fixer` to 1.3

* chore(package): bumped `json-fixer`
@gr2m gr2m unpinned this issue Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants