Ayende @ Rahien

Unnatural acts on source code

NH Prof New Feature: Error Detection

The feature for the day is detecting & notifying the user about NHibernate errors, warning messages and other things that require human attention. As a simple example, let us take this common error:

public class ErrorSavingToDatabase : IScenario
{
    public void Execute(ISessionFactory factory)
    {
        using(var s = factory.OpenSession())
        using(var tx = s.BeginTransaction())
        {
            s.Save(new Blog
            {
                Title = "Will error",
                CreatedAt = DateTime.MinValue// cause error
            });

            tx.Commit();
        }
    }
}

Which will give us:

image 

There are quire a few things going on in here.

First, we can see that NH Prof correctly detected the statement that caused an error and marked it as failed. We can also see the next statement, which give us the actual error details about the actual issue. This means that we have direct access to everything, and can usually understand what is going on very easily, by seeing both the error and the statement that caused it.

This isn’t actually limited to issues that are being raised from exceptions executing SQL queries, there are several cases where NHibernate itself needs to let you know about an issue. In those cases, the profiler will detect and display the message and expose it to you in a visible manner.

Comments

Tomas Restrepo
05/15/2009 02:47 AM by
Tomas Restrepo

Cool feature! Might want to fix the "exeucte", though :)

Kris-I
05/15/2009 03:19 AM by
Kris-I

Cool :)

When these changes will be available ?

Mike
05/15/2009 05:37 AM by
Mike

I was waiting for this feature to get in there...this will help alot.

Krzysztof Kozmic
05/15/2009 08:04 AM by
Krzysztof Kozmic

This is going to be helpful.

especially considering that NHibernate likes to wrap the SQL exceptions into his own AdoExceptions and put some kind of anemic message like "could not execute query".

You then have to drill down into the inner exception to see what the actual problem was.

Comments have been closed on this topic.