Why can't I use blob.readblob(0) on an empty blob?

Just spotted a fringe condition where I might request a zero length sub-blob from an empty blob. Surprised to see that squirrel raises an exception. I would’ve thought it perfectly acceptable to pass readblob a length of 0, when reading from an empty blob. No exception for reading a zero-length blob from a non zero-length blob, however. I think it should just return an empty blob. Is this built into Squirrel or just Electric Imp’s implementation? Neither squirrel-lang.org nor electric imp’s documentation mentions that it would be a problem.

That’s our code - I’ll raise a bug to investigate. Thanks!

This may be related but…

b <- blob(0) server.log(b.tostring())

I would expect this code to return an empty string. Reasonable?
Instead, it returns null

That’s a separate bug, thanks for finding.

Since the latter one doesn’t raise a squirrel error we usually have to be careful not to change behaviour of any deployed squirrel models. In this case though the agent does what you expect, so I think the device should be made to do the same.

The readblob/readstring issue looks fairly straightforward to fix, BTW, but hasn’t been scheduled for the next impOS release. I guess it’s not too inconvenient to code around for now.

You’re welcome,

I think Electric Imp is at a stage where it should consider a known bug list. This page seems to focus on missing functionality. Releases are creeping out to a year apart. I recognise that the platform is mature, and there are fewer bugs to find, but a bug found in 2016 probably won’t be addressed until 2107.

Hoping you meant 2017 vs 2107 :wink:

We are actually working on increasing our impOS release frequency - the aim is to release quarterly. Too long between releases is no good to anyone.

Hmm, just doing some testing of old code and I see that neither of these has been addressed in 34.10

Maybe my mention of 2017 was somewhat prophetic, after all. :wink:

The team agreed that the blob.readblob(0) behaviour is counter-intuitive, but after weighing that up against the possible impact of changing behaviour, decided, with some difficulty, not to change it.

The second issue was fixed by Phil in September, just missing the impOS 34 beta in August. It will be released in impOS 36, which we expect to reach beta as prophesied early in 2017.

impOS 36 is now available for testing