Skip to content

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

Open

Description

@jakebolam

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

Activity

  1. added
    enhancement
    on Jan 26, 2019
  2. Berkmann18 commented on Feb 6, 2019

    @Berkmann18
    Member

    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.

  3. jakebolam commented on Mar 30, 2019

    @jakebolam
    ContributorAuthor

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

  4. changed the title [-]Better error handling when the configuration file is malformed.[/-] [+]Better error handling when the configuration file data structure is incorrect[/+] on May 4, 2019
  5. pinned this issue on May 4, 2019
  6. unpinned this issue on Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions