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

Cannot read property 'height' of undefined #425

Closed
alimousazy opened this Issue Oct 18, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@alimousazy

alimousazy commented Oct 18, 2015

Keep getting this error on all major browser.

@alimousazy

This comment has been minimized.

Show comment
Hide comment
@alimousazy

alimousazy Oct 18, 2015

in elm code
// Returns how many items are in the tree.
function length(array)
{
if (array.height == 0)
{
return array.table.length;
}
else
{
return array.lengths[array.lengths.length - 1];
}
}

alimousazy commented Oct 18, 2015

in elm code
// Returns how many items are in the tree.
function length(array)
{
if (array.height == 0)
{
return array.table.length;
}
else
{
return array.lengths[array.lengths.length - 1];
}
}

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Oct 18, 2015

Contributor

Can you be more specific about the problem, in particular the code that is causing it?

The above does not look like Elm code at all, despite how you introduce it.

So: What is a piece of actual Elm code that gives you a "Cannot read property 'height' of undefined" error?

Contributor

jvoigtlaender commented Oct 18, 2015

Can you be more specific about the problem, in particular the code that is causing it?

The above does not look like Elm code at all, despite how you introduce it.

So: What is a piece of actual Elm code that gives you a "Cannot read property 'height' of undefined" error?

@alimousazy

This comment has been minimized.

Show comment
Hide comment
@alimousazy

alimousazy Oct 18, 2015

TypeError: undefined is not an object (evaluating 'array.height')

http://localhost:8000/elm.js:5482 in length
http://localhost:8000/elm.js:5160 in sliceLeft

https://github.com/Nazanin1369/elm-memoryGame/blob/gh-pages/elm.js#L14

Note: Application works fine for most of the time, but if you hard refresh for a couple of times you will get that error and it will break, link to application

http://nazanin1369.github.io/elm-memoryGame/

alimousazy commented Oct 18, 2015

TypeError: undefined is not an object (evaluating 'array.height')

http://localhost:8000/elm.js:5482 in length
http://localhost:8000/elm.js:5160 in sliceLeft

https://github.com/Nazanin1369/elm-memoryGame/blob/gh-pages/elm.js#L14

Note: Application works fine for most of the time, but if you hard refresh for a couple of times you will get that error and it will break, link to application

http://nazanin1369.github.io/elm-memoryGame/

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Oct 19, 2015

Contributor

So this happens in the project developed at https://github.com/Nazanin1369/elm-memoryGame.

It's difficult to diagnose this issue without a minimal example.

There's three possible cases:

It's possible, in the second and third cases above, that the problem will simply go away as soon as the next version of Elm is released with a fixed version of core. That is about to happen very soon (probably this month), so simply recompiling https://github.com/Nazanin1369/elm-memoryGame with that new version then might already fix the issue.

Addressing the more problematic first case would require more information first: How are the array functions used in https://github.com/Nazanin1369/elm-memoryGame to cause that runtime error?

I suggest you open an issue at the https://github.com/Nazanin1369/elm-memoryGame repo. Describe the error you see and ask the author whether they know what is causing it. Maybe they have already seen this error as well, and knowing their own code, can pinpoint which array functions are to blame. Then it would be very helpful if the author (@Nazanin1369) could open a new issue here in the core repo with a minimal example exhibiting the problem.

I'm closing the current issue here now, since without further information like above there's not much we can do, and if such information becomes available, a new issue would be more appropriate.

Contributor

jvoigtlaender commented Oct 19, 2015

So this happens in the project developed at https://github.com/Nazanin1369/elm-memoryGame.

It's difficult to diagnose this issue without a minimal example.

There's three possible cases:

It's possible, in the second and third cases above, that the problem will simply go away as soon as the next version of Elm is released with a fixed version of core. That is about to happen very soon (probably this month), so simply recompiling https://github.com/Nazanin1369/elm-memoryGame with that new version then might already fix the issue.

Addressing the more problematic first case would require more information first: How are the array functions used in https://github.com/Nazanin1369/elm-memoryGame to cause that runtime error?

I suggest you open an issue at the https://github.com/Nazanin1369/elm-memoryGame repo. Describe the error you see and ask the author whether they know what is causing it. Maybe they have already seen this error as well, and knowing their own code, can pinpoint which array functions are to blame. Then it would be very helpful if the author (@Nazanin1369) could open a new issue here in the core repo with a minimal example exhibiting the problem.

I'm closing the current issue here now, since without further information like above there's not much we can do, and if such information becomes available, a new issue would be more appropriate.

@tino415

This comment has been minimized.

Show comment
Hide comment
@tino415

tino415 May 21, 2018

Today I also encountered this bug, also I failed to find situation in which it happends, exact error is this:

Uncaught TypeError: Cannot read property 'height' of undefined
    at sliceLeft (VM2149 Main.elm:605)
    at sliceLeft (VM2149 Main.elm:614)
    at Function.slice [as func] (VM2149 Main.elm:554)
    at A3 (VM2149 Main.elm:98)
    at Function.func (VM2149 Main.elm:13155)
    at A2 (VM2149 Main.elm:92)
    at Function.func (VM2149 Main.elm:11938)
    at A4 (VM2149 Main.elm:104)
    at VM2149 Main.elm:11990
    at VM2149 Main.elm:26

It happends on this line of compiled elm code (I m testing in elm-reactor):

function sliceLeft(from, a)
{
	if (from === 0)
	{
		return a;
	}

	// Handle leaf level.
	if (a.height === 0) // <- !!!HERE THE ERROR HAPPEND!!!
	{
		var newA = { ctor:'_Array', height:0 };
		newA.table = a.table.slice(from, a.table.length + 1);
		return newA;
	}

	// Slice the left recursively.
	var left = getSlot(from, a);
	var sliced = sliceLeft(from - (left > 0 ? a.lengths[left - 1] : 0), a.table[left]);

	// Maybe the a node is not even needed, as sliced contains the whole slice.
	if (left === a.table.length - 1)
	{
		return sliced;
	}

	// Create new node.
	var newA = {
		ctor: '_Array',
		height: a.height,
		table: a.table.slice(left, a.table.length + 1),
		lengths: new Array(a.table.length - left)
	};
	newA.table[0] = sliced;
	var len = 0;
	for (var i = 0; i < newA.table.length; i++)
	{
		len += length(newA.table[i]);
		newA.lengths[i] = len;
	}

	return newA;
}

It looks like problem is in slice function for array, here is gist with all source code + elm-package.json:
gist I tried to catch error with debug but I was unsucessfull, it feels like (maybe even that are strong words) that when I arrow to end of editing area and then type fast, it happends more often.

I tried to log it out and this is the result:

25 {ctor: "_Array", height: 0, table: Array(24)}
Main.elm:605 26 {ctor: "_Array", height: 0, table: Array(25)}
Main.elm:605 27 {ctor: "_Array", height: 0, table: Array(26)}
Main.elm:605 28 {ctor: "_Array", height: 0, table: Array(27)}
Main.elm:605 29 {ctor: "_Array", height: 0, table: Array(28)}
Main.elm:605 30 {ctor: "_Array", height: 0, table: Array(29)}
Main.elm:605 31 {ctor: "_Array", height: 0, table: Array(30)}
Main.elm:605 32 {ctor: "_Array", height: 0, table: Array(31)}
Main.elm:605 33 {ctor: "_Array", height: 0, table: Array(32)}
Main.elm:605 34 {ctor: "_Array", height: 1, table: Array(2), lengths: Array(2)}
Main.elm:605 1 undefined
Main.elm:606 Uncaught TypeError: Cannot read property 'height' of undefined
    at sliceLeft (Main.elm:606)
    at sliceLeft (Main.elm:615)
    at Function.slice [as func] (Main.elm:554)
    at A3 (Main.elm:98)
    at Function.func (Main.elm:13156)
    at A2 (Main.elm:92)
    at Function.func (Main.elm:11939)
    at A4 (Main.elm:104)
    at Main.elm:11991
    at http://localhost:8000/_compile/Main.elm (old):26:33

tino415 commented May 21, 2018

Today I also encountered this bug, also I failed to find situation in which it happends, exact error is this:

Uncaught TypeError: Cannot read property 'height' of undefined
    at sliceLeft (VM2149 Main.elm:605)
    at sliceLeft (VM2149 Main.elm:614)
    at Function.slice [as func] (VM2149 Main.elm:554)
    at A3 (VM2149 Main.elm:98)
    at Function.func (VM2149 Main.elm:13155)
    at A2 (VM2149 Main.elm:92)
    at Function.func (VM2149 Main.elm:11938)
    at A4 (VM2149 Main.elm:104)
    at VM2149 Main.elm:11990
    at VM2149 Main.elm:26

It happends on this line of compiled elm code (I m testing in elm-reactor):

function sliceLeft(from, a)
{
	if (from === 0)
	{
		return a;
	}

	// Handle leaf level.
	if (a.height === 0) // <- !!!HERE THE ERROR HAPPEND!!!
	{
		var newA = { ctor:'_Array', height:0 };
		newA.table = a.table.slice(from, a.table.length + 1);
		return newA;
	}

	// Slice the left recursively.
	var left = getSlot(from, a);
	var sliced = sliceLeft(from - (left > 0 ? a.lengths[left - 1] : 0), a.table[left]);

	// Maybe the a node is not even needed, as sliced contains the whole slice.
	if (left === a.table.length - 1)
	{
		return sliced;
	}

	// Create new node.
	var newA = {
		ctor: '_Array',
		height: a.height,
		table: a.table.slice(left, a.table.length + 1),
		lengths: new Array(a.table.length - left)
	};
	newA.table[0] = sliced;
	var len = 0;
	for (var i = 0; i < newA.table.length; i++)
	{
		len += length(newA.table[i]);
		newA.lengths[i] = len;
	}

	return newA;
}

It looks like problem is in slice function for array, here is gist with all source code + elm-package.json:
gist I tried to catch error with debug but I was unsucessfull, it feels like (maybe even that are strong words) that when I arrow to end of editing area and then type fast, it happends more often.

I tried to log it out and this is the result:

25 {ctor: "_Array", height: 0, table: Array(24)}
Main.elm:605 26 {ctor: "_Array", height: 0, table: Array(25)}
Main.elm:605 27 {ctor: "_Array", height: 0, table: Array(26)}
Main.elm:605 28 {ctor: "_Array", height: 0, table: Array(27)}
Main.elm:605 29 {ctor: "_Array", height: 0, table: Array(28)}
Main.elm:605 30 {ctor: "_Array", height: 0, table: Array(29)}
Main.elm:605 31 {ctor: "_Array", height: 0, table: Array(30)}
Main.elm:605 32 {ctor: "_Array", height: 0, table: Array(31)}
Main.elm:605 33 {ctor: "_Array", height: 0, table: Array(32)}
Main.elm:605 34 {ctor: "_Array", height: 1, table: Array(2), lengths: Array(2)}
Main.elm:605 1 undefined
Main.elm:606 Uncaught TypeError: Cannot read property 'height' of undefined
    at sliceLeft (Main.elm:606)
    at sliceLeft (Main.elm:615)
    at Function.slice [as func] (Main.elm:554)
    at A3 (Main.elm:98)
    at Function.func (Main.elm:13156)
    at A2 (Main.elm:92)
    at Function.func (Main.elm:11939)
    at A4 (Main.elm:104)
    at Main.elm:11991
    at http://localhost:8000/_compile/Main.elm (old):26:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment