Browse Source

Improving some exception messages for AsyncEnumerable operators.

Bart De Smet 10 years ago
parent
commit
d0654b94be

+ 13 - 13
Ix.NET/Source/System.Interactive.Async/AsyncEnumerable.Aggregates.cs

@@ -113,7 +113,7 @@ namespace System.Linq
                     else
                     {
                         if (first)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(acc);
                     }
@@ -288,7 +288,7 @@ namespace System.Linq
                     if (res)
                         tcs.TrySetResult(e.Current);
                     else
-                        tcs.TrySetException(new InvalidOperationException());
+                        tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                 });
             });
 
@@ -363,7 +363,7 @@ namespace System.Linq
                     else
                     {
                         if (!hasLast)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(last);
                     }
@@ -453,14 +453,14 @@ namespace System.Linq
                             t1.Handle(tcs, res1 =>
                             {
                                 if (res1)
-                                    tcs.TrySetException(new InvalidOperationException());
+                                    tcs.TrySetException(new InvalidOperationException(Strings.MORE_THAN_ONE_ELEMENT));
                                 else
                                     tcs.TrySetResult(result);
                             });
                         });
                     }
                     else
-                        tcs.TrySetException(new InvalidOperationException());
+                        tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                 });
             });
 
@@ -498,7 +498,7 @@ namespace System.Linq
                             t1.Handle(tcs, res1 =>
                             {
                                 if (res1)
-                                    tcs.TrySetException(new InvalidOperationException());
+                                    tcs.TrySetException(new InvalidOperationException(Strings.MORE_THAN_ONE_ELEMENT));
                                 else
                                     tcs.TrySetResult(result);
                             });
@@ -552,7 +552,7 @@ namespace System.Linq
                     }
                     else
                     {
-                        tcs.TrySetException(new ArgumentOutOfRangeException());
+                        tcs.TrySetException(new ArgumentOutOfRangeException("index"));
                     }
                 });
             });
@@ -787,7 +787,7 @@ namespace System.Linq
                     else
                     {
                         if (count == 0)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(sum / count);
                     }
@@ -866,7 +866,7 @@ namespace System.Linq
                     else
                     {
                         if (count == 0)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(sum / count);
                     }
@@ -945,7 +945,7 @@ namespace System.Linq
                     else
                     {
                         if (count == 0)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(sum / count);
                     }
@@ -1024,7 +1024,7 @@ namespace System.Linq
                     else
                     {
                         if (count == 0)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(sum / count);
                     }
@@ -1103,7 +1103,7 @@ namespace System.Linq
                     else
                     {
                         if (count == 0)
-                            tcs.TrySetException(new InvalidOperationException());
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                         else
                             tcs.TrySetResult(sum / count);
                     }
@@ -1951,7 +1951,7 @@ namespace System.Linq
                     {
                         if (!res)
                         {
-                            tcs.TrySetException(new InvalidOperationException("Source sequence doesn't contain any elements."));
+                            tcs.TrySetException(new InvalidOperationException(Strings.NO_ELEMENTS));
                             return;
                         }
 

+ 9 - 0
Ix.NET/Source/System.Interactive.Async/Strings.cs

@@ -0,0 +1,9 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
+namespace System.Linq
+{
+    internal static class Strings
+    {
+        public static string NO_ELEMENTS = "Source sequence doesn't contain any elements.";
+        public static string MORE_THAN_ONE_ELEMENT = "Source sequence contains more than one element.";
+    }
+}

+ 1 - 0
Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj

@@ -54,6 +54,7 @@
     <Compile Include="IAsyncGrouping.cs" />
     <Compile Include="IOrderedAsyncEnumerable.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Strings.cs" />
     <Compile Include="TaskExt.cs" />
   </ItemGroup>
   <Import Project="..\Import.targets" />