From b9101c8dc34b432f04adc076acaabcf62283c5e4 Mon Sep 17 00:00:00 2001
From: Alec Theriault <alec.theriault@gmail.com>
Date: Fri, 10 Aug 2018 16:24:56 -0700
Subject: [PATCH] 'Binary (NonEmpty a)' should 'fail' on empty lists

The failure should be in the context of 'MonadFail'.
---
 src/Data/Binary/Class.hs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/Data/Binary/Class.hs b/src/Data/Binary/Class.hs
index 2eed93e..3bec014 100644
--- a/src/Data/Binary/Class.hs
+++ b/src/Data/Binary/Class.hs
@@ -830,7 +830,11 @@ instance (Binary a, Binary b) => Binary (Semigroup.Arg a b) where
 
 -- | /Since: 0.8.4.0/
 instance Binary a => Binary (NE.NonEmpty a) where
-  get = fmap NE.fromList get
+  get = do
+      list <- get
+      case list of
+        [] -> fail "NonEmpty is actually empty!"
+        x:xs -> pure (x NE.:| xs)
   put = put . NE.toList
 #endif
 
-- 
GitLab