github-repo-size icon indicating copy to clipboard operation
github-repo-size copied to clipboard

Fix bug: table update error while using file view

Open msvamp opened this issue 5 years ago • 2 comments

The extension tried to update file sizes even when a directory page was not being browsed, which led to error TypeError: tree.forEach is not a function on line 153 (line number before this pull request) For example, visit page: https://github.com/harshjv/github-repo-size/blob/master/src/inject.js and check extension errors.

This is now fixed by detecting directory view with the presence of the 'Add file' button and updating table only if the button is present.

Also, removed redundant CSS 'cursor: pointer' for newLiElem.

msvamp avatar Jun 24 '20 13:06 msvamp

@msvamp thank you for the update!

Can you please share steps to reproduce TypeError: tree.forEach is not a function error?

harshjv avatar Sep 22 '20 06:09 harshjv

Sure. The steps are pretty simple.

Steps to reproduce

  1. Ensure the extension is enabled and Chrome Extensions Developer mode is enabled
  2. If the unpacked extension is being run, skip this step. But if one is running the extension from the webstore, Chrome will ignore all errors by default. So, visit chrome://extensions/?id=apnjnioapinblneaedefcnopcjepgkci and enable the Collect Errors switch.
  3. Now, visit the page corresponding to any file (not folder) in any GitHub repository. For example, the license file of this repository.
  4. Go to chrome://extensions/?errors=apnjnioapinblneaedefcnopcjepgkci and the error should be there. Error in Extensions section

Steps to reproduce (alternate)

Alternately, the same error is also visible in the console section of the Developer Tools on visiting the same page. Error in Extensions section

What causes the error?

When a request is made to GitHub API for a directory in a repo or the root of the repo, the response contains the corresponding details of all files in the folder in the the form of an array of JSON objects.

Example request: https://api.github.com/repos/harshjv/github-repo-size/contents/?ref=f82f23b9a2c18afdd824cc0b89b1d909b9a090f9 API Response (folder)

But when a request is made for a file in a repo, the response contains a single JSON object with the details of the single file, and hence the forEach operation fails.

Example request: https://api.github.com/repos/harshjv/github-repo-size/contents/LICENSE.md?ref=f82f23b9a2c18afdd824cc0b89b1d909b9a090f9 API Response (file)

msvamp avatar Sep 23 '20 16:09 msvamp