Repository: dask/dask

Issue:
len(dask scalar) gives an error
```
Traceback (most recent call last):
  File "make-pkhalo.py", line 12, in <module>
    print(cath200['Mass'][0])
  File "/home/yfeng1/anaconda3/install/envs/cfastpm/lib/python3.6/site-packages/nbodykit/base/catalog.py", line 75, in __str__
    if len(self) > 0:
  File "/home/yfeng1/anaconda3/install/envs/cfastpm/lib/python3.6/site-packages/dask/array/core.py", line 1064, in __len__
    return sum(self.chunks[0])
IndexError: tuple index out of range
```

The error is probably valid as self is a scalar, but the message could be more informative than an out of range index error. 

Discussion:
jcrist: LGTM. Thanks @metasyn!

Patch:
diff --git a/dask/array/core.py b/dask/array/core.py
index af23cc282..d7a944784 100644
--- a/dask/array/core.py
+++ b/dask/array/core.py
@@ -1111,6 +1111,8 @@ class Array(Base):
     chunks = property(_get_chunks, _set_chunks, "chunks property")
 
     def __len__(self):
+        if not self.chunks:
+            raise TypeError("len() of unsized object")
         return sum(self.chunks[0])
 
     def __array_ufunc__(self, numpy_ufunc, method, *inputs, **kwargs):
diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst
index e789593ba..823f70472 100644
--- a/docs/source/changelog.rst
+++ b/docs/source/changelog.rst
@@ -7,7 +7,7 @@ Changelog
 
 Array
 +++++
-
+- Update error handling when len is called with empty chunks (:issue:`3058`) `Xander Johnson`_
 
 DataFrame
 +++++++++
@@ -918,3 +918,4 @@ Other
 .. _`Markus Gonser`: https://github.com/magonser
 .. _`Martijn Arts`: https://github.com/mfaafm
 .. _`Jon Mease`: https://github.com/jmmease
+.. _`Xander Johnson`: https://github.com/metasyn


Test patch:
diff --git a/dask/array/tests/test_array_core.py b/dask/array/tests/test_array_core.py
index 0eececc3c..a5c76c46d 100644
--- a/dask/array/tests/test_array_core.py
+++ b/dask/array/tests/test_array_core.py
@@ -3032,3 +3032,12 @@ def test_delayed_array_key_hygeine():
     d = delayed(identity)(a)
     b = da.from_delayed(d, shape=a.shape, dtype=a.dtype)
     assert_eq(a, b)
+
+
+def test_empty_chunks_in_array_len():
+    x = da.ones((), chunks=())
+    with pytest.raises(TypeError) as exc_info:
+        len(x)
+
+    err_msg = 'len() of unsized object'
+    assert err_msg in str(exc_info.value)