Skip to content

Commit

Permalink
Replace NotImplementedException with NotSupportedException (#23502)
Browse files Browse the repository at this point in the history
Fixes #20961

> You might choose to throw a NotImplementedException exception in properties or methods in your own types when the that member is still in development and will only later be implemented in production code. In other words, a NotImplementedException exception should be synonymous with "still in development."

I left one NotImplementedException in Migration.cs, because it really is there for when the application hasn't implemented Down yet, but tries to do a Down.
  • Loading branch information
ajcvickers committed Dec 20, 2020
1 parent a48bfd1 commit 7a8cb44
Show file tree
Hide file tree
Showing 44 changed files with 248 additions and 143 deletions.
12 changes: 12 additions & 0 deletions src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/EFCore.Cosmos/Properties/CosmosStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CanConnectNotSupported" xml:space="preserve">
<value>The Cosmos database does not support 'CanConnect' or 'CanConnectAsync'.</value>
</data>
<data name="ConnectionStringConflictingConfiguration" xml:space="preserve">
<value>Both the connection string and account key or account endpoint were specified. Specify only one set of connection details.</value>
</data>
Expand Down Expand Up @@ -215,6 +218,9 @@
<data name="ReverseAfterSkipTakeNotSupported" xml:space="preserve">
<value>Reversing the ordering is not supported when limit or offset are already applied.</value>
</data>
<data name="TransactionsNotSupported" xml:space="preserve">
<value>The Cosmos database provider does not support transactions.</value>
</data>
<data name="UnableToBindMemberToEntityProjection" xml:space="preserve">
<value>Unable to bind '{memberType}' '{member}' to an entity projection of '{entityType}'.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void Dispose()
}

public void Reset()
=> throw new NotImplementedException();
=> throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
}

private sealed class AsyncEnumerator : IAsyncEnumerator<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public ValueTask DisposeAsync()
}

public void Reset()
=> throw new NotImplementedException();
=> throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);

private bool ShapeResult()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq.Expressions;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Utilities;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -110,7 +111,7 @@ protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQuery
QueryCompilationContext.QueryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution));

default:
throw new NotImplementedException();
throw new NotSupportedException(CoreStrings.UnhandledExpressionNode(shapedQueryExpression.QueryExpression));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public void Dispose()
}

public void Reset()
=> throw new NotImplementedException();
=> throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Update;
Expand Down Expand Up @@ -167,7 +168,7 @@ public virtual Task<bool> EnsureDeletedAsync(CancellationToken cancellationToken
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool CanConnect()
=> throw new NotImplementedException();
=> throw new NotSupportedException(CosmosStrings.CanConnectNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -176,7 +177,7 @@ public virtual bool CanConnect()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
=> throw new NotImplementedException();
=> throw new NotSupportedException(CosmosStrings.CanConnectNotSupported);

/// <summary>
/// Returns the store name of the property that is used to store the partition key.
Expand Down
15 changes: 8 additions & 7 deletions src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal
Expand All @@ -24,7 +25,7 @@ public class CosmosTransactionManager : IDbContextTransactionManager, ITransacti
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IDbContextTransaction BeginTransaction()
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -34,7 +35,7 @@ public virtual IDbContextTransaction BeginTransaction()
/// </summary>
public virtual Task<IDbContextTransaction> BeginTransactionAsync(
CancellationToken cancellationToken = default)
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -43,7 +44,7 @@ public virtual Task<IDbContextTransaction> BeginTransactionAsync(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void CommitTransaction()
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -52,7 +53,7 @@ public virtual void CommitTransaction()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual Task CommitTransactionAsync(CancellationToken cancellationToken = default)
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -61,7 +62,7 @@ public virtual Task CommitTransactionAsync(CancellationToken cancellationToken =
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void RollbackTransaction()
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -70,7 +71,7 @@ public virtual void RollbackTransaction()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual Task RollbackTransactionAsync(CancellationToken cancellationToken = default)
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -97,7 +98,7 @@ public virtual Transaction EnlistedTransaction
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void EnlistTransaction(Transaction transaction)
=> throw new NotSupportedException();
=> throw new NotSupportedException(CosmosStrings.TransactionsNotSupported);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public ValueTask DisposeAsync()
}

public void Reset()
=> throw new NotImplementedException();
=> throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ public static IEnumerable<IForeignKey> FindRowInternalForeignKeys(

break;
default:
throw new NotImplementedException(storeObject.StoreObjectType.ToString());
throw new NotSupportedException(storeObject.StoreObjectType.ToString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in

break;
default:
throw new NotImplementedException(storeObject.StoreObjectType.ToString());
throw new NotSupportedException(storeObject.StoreObjectType.ToString());
}

if (entityType == null)
Expand Down Expand Up @@ -456,7 +456,7 @@ public static IColumnBase FindColumn([NotNull] this IProperty property, in Store

return null;
default:
throw new NotImplementedException(storeObject.StoreObjectType.ToString());
throw new NotSupportedException(storeObject.StoreObjectType.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ protected virtual void ValidatePropertyOverrides(

break;
default:
throw new NotImplementedException(storeOverride.StoreObjectType.ToString());
throw new NotSupportedException(storeOverride.StoreObjectType.ToString());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/RelationalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ public static ReferentialAction ToReferentialAction(DeleteBehavior deleteBehavio
case DeleteBehavior.ClientCascade:
return ReferentialAction.Restrict;
default:
throw new NotImplementedException(deleteBehavior.ToString());
throw new NotSupportedException(deleteBehavior.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -874,7 +874,7 @@ public bool Equals(PropertyInfo x, PropertyInfo y)
=> x.IsSameAs(y);

public int GetHashCode(PropertyInfo obj)
=> throw new NotImplementedException();
=> throw new NotSupportedException();
}

#endregion
Expand Down
5 changes: 2 additions & 3 deletions src/EFCore.Relational/Migrations/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations.Operations;

Expand Down Expand Up @@ -118,9 +119,7 @@ protected virtual void BuildTargetModel([NotNull] ModelBuilder modelBuilder)
/// </summary>
/// <param name="migrationBuilder"> The <see cref="MigrationBuilder" /> that will build the operations. </param>
protected virtual void Down([NotNull] MigrationBuilder migrationBuilder)
{
throw new NotImplementedException();
}
=> throw new NotSupportedException(RelationalStrings.MigrationDownMissing);

private List<MigrationOperation> BuildOperations(Action<MigrationBuilder> buildAction)
{
Expand Down
Loading

0 comments on commit 7a8cb44

Please sign in to comment.