Missing undefined check in JavaScript SDK

#1

The txns property is {} in several blocks (e.g. 329923). Calling:
let block = await algodClient.block(i);

Results in the following error:
TypeError: Cannot read property 'length' of undefined in algod.js.

Suggested fix is to check for this case before getting the upper limit of the for loop:
if (res.statusCode === 200 && typeof res.body.txns.transactions !== "undefined") {

Sincerely,
Jimmy

2 Likes
#2

Great catch Jimmy. I will update the example.

#3

I meant to say we will update the source. Thanks for finding this.

#4

Cool and there are other functions that might need the same.
Just curious, what is special/different about these blocks?

As a side note, since I have your ear. I cannot roll up a release of an CLI app that incorporates the Go SDK using ‘dep’ because algorand/go-codec is still private on Github. I see the source in the vendor/ subdirectory. However since it’s a dependency in the SDK’s Gopkg.toml, then ‘dep’ dies. I’m not sure what enhancements you’ve made over ugorji/go-codec, hopefully you’ll consider releasing it.

Cheers,
Jimmy

#5

Jimmy,

All transaction loops will need be checked like that. That is a block with no transactions.
On the Go SDK packaging, I am checking on this.

#6

Jimmy,

go-codec should now be public. Can you let us know if this worked?

#7

Worked on the first try! Thanks for that.

Jimmy