Skip to content

Crash when adding contributors and there is no content before the all contributors comment tag #376

@davepagurek

Description

@davepagurek

Describe the bug
At p5.js we just switched to having our contributors list in a separate file because it was getting quite large. We noticed after doing this that the all-contributors bot stopped being able to add contributors. The problem could be reproduced with the all-contributors CLI locally too. It worked correctly again after adding a title to the markdown file.

To Reproduce
Steps to reproduce the behavior:

  1. Create CONTRIBUTORS.md that looks like this, with nothing at the top of the file before the comment:

    <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
    <!-- prettier-ignore-start -->
    <!-- markdownlint-disable -->
    
    <!-- markdownlint-restore -->
    <!-- prettier-ignore-end -->
    <!-- ALL-CONTRIBUTORS-LIST:END -->
  2. In .all-contributorsrc, point to that file:

    "files": [
       "CONTRIBUTORS.md"
     ],
  3. Run all-contributors add someusername code to try to add a contributor

  4. I get this error:

  RangeError: Invalid count value: -1
      at String.repeat (<anonymous>)
      at /usr/local/lib/node_modules/all-contributors-cli/dist/generate/index.js:19:186
      at /usr/local/lib/node_modules/all-contributors-cli/node_modules/lodash/lodash.min.js:57:276
      at module.exports (/usr/local/lib/node_modules/all-contributors-cli/dist/generate/index.js:75:78)
      at /usr/local/lib/node_modules/all-contributors-cli/dist/cli.js:33:28
      at async Promise.all (index 0)

Expected behavior
It should be able to add an entry to the table.

Additional context
Adding anything beforehand, e.g. a title to the markdown file, makes it work.

I think there's just an assumption that there is content before, so it tries to index a string at index -1. Maybe wrapping in Math.max(idx, 0) would be sufficient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions