Skip to content

Commit

Permalink
Merge pull request #1910 from glopesdev/dag-exceptions
Browse files Browse the repository at this point in the history
Fix exception constructor argument order
  • Loading branch information
glopesdev authored Jul 16, 2024
2 parents 58f8c08 + f4fe28d commit ab59036
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ dotnet_sort_system_directives_first = true
# Predefined for members, etc does not create a message because the explicitly sized types are conveient in interop scenarios where the bit size matters.
dotnet_style_predefined_type_for_locals_parameters_members = true:none
dotnet_style_predefined_type_for_member_access = true:suggestion

# Instantiate argument exceptions correctly
dotnet_diagnostic.CA2208.severity = warning
24 changes: 12 additions & 12 deletions Bonsai.Core/Dag/DirectedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Edge<TNodeValue, TEdgeLabel> InsertEdge(Node<TNodeValue, TEdgeLabel> from
ThrowIfEdgeVerticesNullOrNotInGraph(from, to, nameof(to));
if (edgeIndex < 0 || edgeIndex > from.Successors.Count)
{
throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex));
throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range.");
}

var edge = new Edge<TNodeValue, TEdgeLabel>(to, label);
Expand All @@ -216,7 +216,7 @@ public void InsertEdge(Node<TNodeValue, TEdgeLabel> from, int edgeIndex, Edge<TN
ThrowIfEdgeVerticesNullOrNotInGraph(from, edge?.Target, nameof(edge));
if (edgeIndex < 0 || edgeIndex > from.Successors.Count)
{
throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex));
throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range.");
}

from.Successors.Insert(edgeIndex, edge);
Expand All @@ -238,7 +238,7 @@ public Edge<TNodeValue, TEdgeLabel> SetEdge(Node<TNodeValue, TEdgeLabel> from, i
ThrowIfEdgeVerticesNullOrNotInGraph(from, to, nameof(to));
if (edgeIndex < 0 || edgeIndex >= from.Successors.Count)
{
throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex));
throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range.");
}

var edge = new Edge<TNodeValue, TEdgeLabel>(to, label);
Expand All @@ -263,7 +263,7 @@ public void SetEdge(Node<TNodeValue, TEdgeLabel> from, int edgeIndex, Edge<TNode
ThrowIfEdgeVerticesNullOrNotInGraph(from, edge?.Target, nameof(edge));
if (edgeIndex < 0 || edgeIndex >= from.Successors.Count)
{
throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex));
throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range.");
}

from.Successors[edgeIndex] = edge;
Expand Down Expand Up @@ -313,7 +313,7 @@ public Node<TNodeValue, TEdgeLabel> Insert(int index, TNodeValue value)
{
if (index < 0 || index > nodes.Count)
{
throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range.");
}

var node = new Node<TNodeValue, TEdgeLabel>(value);
Expand Down Expand Up @@ -343,7 +343,7 @@ public void Insert(int index, Node<TNodeValue, TEdgeLabel> node)

if (index < 0 || index > nodes.Count)
{
throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range.");
}

InsertInternal(index, new[] { node });
Expand Down Expand Up @@ -375,7 +375,7 @@ public void InsertRange(int index, IEnumerable<Node<TNodeValue, TEdgeLabel>> col

if (index < 0 || index > nodes.Count)
{
throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range.");
}

InsertInternal(index, collection);
Expand Down Expand Up @@ -471,7 +471,7 @@ public void RemoveAt(int index)
{
if (index < 0 || index >= nodes.Count)
{
throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range.");
}

var node = nodes[index];
Expand Down Expand Up @@ -524,19 +524,19 @@ public void RemoveRange(int index, int count)
{
if (index < 0)
{
throw new ArgumentOutOfRangeException("The specified index is less than zero.", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), "The specified index is less than zero.");
}

if (count < 0)
{
throw new ArgumentOutOfRangeException("The count of elements to remove is less than zero.", nameof(count));
throw new ArgumentOutOfRangeException(nameof(count), "The count of elements to remove is less than zero.");
}

if (nodes.Count - index < count)
{
throw new ArgumentOutOfRangeException(
"The index and count were out of bounds or count is greater than the number of nodes from index.",
nameof(count));
nameof(count),
"The index and count were out of bounds or count is greater than the number of nodes from index.");
}

var removed = new HashSet<Node<TNodeValue, TEdgeLabel>>();
Expand Down
6 changes: 3 additions & 3 deletions Bonsai.Core/Reactive/Slice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ public override IObservable<TSource> Process<TSource>(IObservable<TSource> sourc
var start = Start;
if (start < 0)
{
throw new ArgumentOutOfRangeException(nameof(start));
throw new InvalidOperationException("The specified start index is less than zero.");
}

var step = Step;
if (step <= 0)
{
throw new ArgumentOutOfRangeException(nameof(step));
throw new InvalidOperationException("Step size must be a positive number.");
}

var stop = Stop;
if (stop < 0)
{
throw new ArgumentOutOfRangeException(nameof(stop));
throw new InvalidOperationException("The specified stop index is less than zero.");
}

return (stop - start) <= 0 ? Observable.Empty<TSource>() : Observable.Create<TSource>(observer =>
Expand Down

0 comments on commit ab59036

Please sign in to comment.