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

Uncaught RangeError: Chance: Min cannot be greater than Max. #47

Closed
danb235 opened this issue Mar 20, 2014 · 8 comments · Fixed by #52
Closed

Uncaught RangeError: Chance: Min cannot be greater than Max. #47

danb235 opened this issue Mar 20, 2014 · 8 comments · Fixed by #52

Comments

@danb235
Copy link

danb235 commented Mar 20, 2014

We got gremlins up and running (neat project, btw) but are encountering an error after a second or two of testing. I was hoping for some insight.

Uncaught RangeError: Chance: Min cannot be greater than Max. gremlins.min.js?bust=1395340612814:22
f gremlins.min.js?bust=1395340612814:22
u.natural gremlins.min.js?bust=1395340612814:22
u.pick gremlins.min.js?bust=1395340612814:22
l gremlins.min.js?bust=1395340612814:22
u gremlins.min.js?bust=1395340612814:22
s gremlins.min.js?bust=1395340612814:22
t gremlins.min.js?bust=1395340612814:22
p gremlins.min.js?bust=1395340612814:22
(anonymous function)

Here is a screenshot of my chrome dev console with the error:

screen shot 2014-03-20 at 11 37 16 am

Any suggestions?

@fzaninotto
Copy link
Member

Can't reproduce. Could you share the test page you run gremlins on? Could you paste the detailed error stack when using the non-minified version of gremlins?

@alexeygolev
Copy link

same thing here

@fzaninotto
Copy link
Member

Same comment: can you help me reproduce the bug?

@gabehayes
Copy link

After rebuilding the js file with the optimize property set to none, then running the test, here is the stack for the error:

Uncaught RangeError: Chance: Min cannot be greater than Max. gremlins.min.js?bust=1395780871173:481
testRange gremlins.min.js?bust=1395780871173:481
Chance.natural gremlins.min.js?bust=1395780871173:603
Chance.pick gremlins.min.js?bust=1395780871173:662
fillSelect gremlins.min.js?bust=1395780871173:2002
formFillerGremlin gremlins.min.js?bust=1395780871173:1975
iterator gremlins.min.js?bust=1395780871173:2564
executeInSeries gremlins.min.js?bust=1395780871173:2576
executeNext gremlins.min.js?bust=1395780871173:2789
(anonymous function) gremlins.min.js?bust=1395780871173:2791

Looks like the error is being thrown by this method in chancejs:

    function testRange(test, errorMessage) {
        if (test) {
            throw new RangeError(errorMessage);
        }
    }

Which means that the passed options here are invalid?

    // NOTE the max and min are INCLUDED in the range. So:
    //
    // chance.natural({min: 1, max: 3});
    //
    // would return either 1, 2, or 3.

    Chance.prototype.natural = function (options) {

        // 9007199254740992 (2^53) is the max integer number in JavaScript
        // See: http://vq.io/132sa2j
        options = initOptions(options, {min: 0, max: MAX_INT});

        testRange(options.min > options.max, "Chance: Min cannot be greater than Max.");

        return Math.floor(this.random() * (options.max - options.min + 1) + options.min);
    };

Happens every time we launch. Loading the module via requirejs and launching with gremlins.createHorde().unleash().

After looking at the stack, please let me know if there are any specific variables you care for us to log.

@JaSpr
Copy link

JaSpr commented Mar 25, 2014

where is MAX_INT getting defined?

@gabehayes
Copy link

I haven't traced exactly where it is getting defined, yet, but it's value is as the comment indicates: 9007199254740992

image

The issue definitely seems to be with chance's handling of picking a random item. For some reason at a given moment, element.querySelectorAll('option') returns no items:

image

Then, calling pick (with the count argument not defined), it is setting the max value to be -1:

image

Which then leads to this error being called by chance's natural method, because the range is invalid:

image

@fzaninotto
Copy link
Member

Thanks, you helped me find a bug in case a page contains an empty select. Should be fixed by #52.

@gabehayes
Copy link

👍 awesome work, thanks for taking care of that.

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 a pull request may close this issue.

5 participants