Skip to content

Fix error when there are no config files #183

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

Merged
merged 1 commit into from
Feb 28, 2017
Merged

Fix error when there are no config files #183

merged 1 commit into from
Feb 28, 2017

Conversation

gdiggs
Copy link
Contributor

@gdiggs gdiggs commented Feb 28, 2017

Fixes the following error:

  TypeError: Reduce of empty array with no initial value
      at Array.reduce (native)
      at Function.upgradeInstructions (/usr/src/app/lib/config_upgrader.js:272:20)
      at Object.<anonymous> (/usr/src/app/bin/eslint.js:239:37)
      at Module._compile (module.js:556:32)
      at Object.Module._extensions..js (module.js:565:10)
      at Module.load (module.js:473:32)
      at tryModuleLoad (module.js:432:12)
      at Function.Module._load (module.js:424:3)
      at Module.runMain (module.js:590:10)
      at run (bootstrap_node.js:394:7)

I couldn't find a good initial value to give to reduce to obtain the
correct functionality. There's no reason to reduce anyway if there are
no reports.

Fixes the following error:

      TypeError: Reduce of empty array with no initial value
          at Array.reduce (native)
          at Function.upgradeInstructions (/usr/src/app/lib/config_upgrader.js:272:20)
          at Object.<anonymous> (/usr/src/app/bin/eslint.js:239:37)
          at Module._compile (module.js:556:32)
          at Object.Module._extensions..js (module.js:565:10)
          at Module.load (module.js:473:32)
          at tryModuleLoad (module.js:432:12)
          at Function.Module._load (module.js:424:3)
          at Module.runMain (module.js:590:10)
          at run (bootstrap_node.js:394:7)

I couldn't find a good initial value to give to `reduce` to obtain the
correct functionality. There's no reason to reduce anyway if there are
no reports.
@gdiggs gdiggs requested review from maxjacobson and chrishulton and removed request for maxjacobson February 28, 2017 16:50
Copy link

@nporteschaikin nporteschaikin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -269,7 +269,11 @@ class ConfigUpgrader {
return report;
});

return reports.reduce(function(a, b) { return a.concat([""]).concat(b); });
if (reports.length > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also simply do if (reports.length) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the explicitness of > 0 here. The fact that 0 is falsy makes me squirm heh

@gdiggs gdiggs merged commit 9f6054c into master Feb 28, 2017
@gdiggs gdiggs deleted the gd-reduce branch February 28, 2017 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants