Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Throw better exception when reading incorrect data for relational providers #6471

Closed
ErikEJ opened this issue Sep 4, 2016 · 8 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 4, 2016

Steps to reproduce

Running the OptimisticConcurrencyTestBase tests with the SQLCE 1.1 alpha provider

The issue

Instead of the expected InvalidOperationException, InvalidCastException is thrown (from the ADO.NET provider)

Test 'Microsoft.EntityFrameworkCore.Specification.Tests.FromSqlQuerySqlCeTest.Bad_data_error_handling_invalid_cast_key' failed:
    Assert.Throws() Failure
Expected: typeof(System.InvalidOperationException)
Actual:   typeof(System.InvalidCastException): Specified cast is not valid.
    at System.Data.SqlServerCe.SqlCeDataReader.GetInt32(Int32 ordinal)
    at lambda_method(Closure , DbDataReader )
    at Microsoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
    at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
    at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
    at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
    at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    at Microsoft.EntityFrameworkCore.Specification.Tests.FromSqlQueryTestBase`1.<>c__DisplayClass0_0.<Bad_data_error_handling_invalid_cast_key>b__0()

Further technical details

EF Core version: 1.1.0-alpha1-21973
Operating system: Win 10
Visual Studio version: VS 2015 Update 3

@ajcvickers
Copy link
Contributor

@ErikEJ I think this is fine. The point of this test was to throw with a better message for providers that grab the value from the data reader as an object. I believe that currently this is only SQL Server. Every other provider will throw when reading out of the data reader. This is why the test is skipped for SQLite.

@ajcvickers
Copy link
Contributor

However, @divega or @anpete may want to comment. Maybe the intention was for this message to be used for all providers, but if so then it doesn't make sense that the test would be skipped for SQLite.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Sep 6, 2016

@ajcvickers Thanks, yes, I saw the tests were disabled for sqlite, but I was also unsure abot the purpose of the introduced message - since it is in Relational, and not in the SQL Server provider

@divega divega changed the title unexpected excpetion from test with the SQLCE provider unexpected excepetion from test with the SQLCE provider Sep 6, 2016
@divega divega changed the title unexpected excepetion from test with the SQLCE provider unexpected exception from test with the SQLCE provider Sep 6, 2016
@divega
Copy link
Contributor

divega commented Sep 6, 2016

AFAIR it is how @ajcvickers said. I guess we could add a comment somewhere in these tests to clarify the intent to provider writers.

Also I am thinking we could refactor the tests to allow provider writers to override the assertion and match whatever exception their providers would throw. At least that way provider writers would have a chance to asses if the exception is clear enough or if they want to do something specific in their providers to throw a better exception. But I am not sure there is enough value in that.

@ErikEJ ErikEJ closed this as completed Sep 7, 2016
@anpete
Copy link
Contributor

anpete commented Sep 9, 2016

Initial thought is that we should make the improved error handling work for these providers, too. I can't remember whether there was something fundamental blocking it, but it looks like we just need to gen the try/catch stuff in TypedRelationalValueBufferFactoryFactory. Re-opening.

@anpete anpete reopened this Sep 9, 2016
@rowanmiller rowanmiller added this to the 1.1.0 milestone Sep 12, 2016
@rowanmiller rowanmiller changed the title unexpected exception from test with the SQLCE provider Throw better exception when reading incorrect data for relational providers Sep 12, 2016
@hkoestin
Copy link

Don't know if this is related to this issue, but I also have encountered the InvalidCastException on the SQL Server relational provider, which does not provide any additional information nor meaning. Just from the message, I can't figure out, which of the columns from the SQL cannot be handled correctly.

A message would be good to show, which of the columns is actually causing the problem.

Here is the log output of the EF ILoggerProvider:
7 Debug 2016-09-21 09:48:11.8136 EF-SQL An exception occurred in the database while iterating the results of a query. System.InvalidCastException: Specified cast is not valid. at lambda_method(Closure , Object[] ) at Microsoft.EntityFrameworkCore.Storage.Internal.UntypedRelationalValueBufferFactory.Create(DbDataReader dataReader) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext() at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__31.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext()

Screenshot from the VS debugger:
image

@anpete
Copy link
Contributor

anpete commented Sep 28, 2016

@hkoestin Which version of EF Core?

@maumar maumar modified the milestones: 1.2.0, 1.1.0-preview1 Oct 5, 2016
@hkoestin
Copy link

hkoestin commented Oct 7, 2016

Sorry for the late reply. It is core 1.0.1 with relational provider 1.0.1
(sql-server and sqlite)

On Wed, Sep 28, 2016 at 8:03 PM, Andrew Peters [email protected]
wrote:

@hkoestin https://github.com/hkoestin Which version of EF Core?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#6471 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANNVExlisU3Zj8udOwUlFK5PVdiRHrKfks5quqvtgaJpZM4J0lxQ
.

anpete added a commit that referenced this issue Oct 17, 2016
…pedValueBufferFactoryFactory

- Added the try/catch logic to TypedValueBufferFactoryFactory and figured out how to test it.
anpete added a commit that referenced this issue Oct 18, 2016
…pedValueBufferFactoryFactory

- Added the try/catch logic to TypedValueBufferFactoryFactory and figured out how to test it.
anpete added a commit that referenced this issue Oct 18, 2016
…pedValueBufferFactoryFactory

- Added the try/catch logic to TypedValueBufferFactoryFactory and figured out how to test it.
anpete added a commit that referenced this issue Oct 24, 2016
…pedValueBufferFactoryFactory

- Added the try/catch logic to TypedValueBufferFactoryFactory and figured out how to test it.
@anpete anpete closed this as completed Oct 26, 2016
smitpatel pushed a commit that referenced this issue Nov 8, 2016
…pedValueBufferFactoryFactory

- Added the try/catch logic to TypedValueBufferFactoryFactory and figured out how to test it.
@divega divega added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 8, 2017
@ajcvickers ajcvickers changed the title Throw better exception when reading incorrect data for relational providers Query: Throw better exception when reading incorrect data for relational providers May 9, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

7 participants