Nancy: The confusing error message when Internal Server Error

Created on 30 Oct 2016  ·  5Comments  ·  Source: NancyFx/Nancy

Hi, I have a request rather than a bug report.
When the code threw an exception, I got this page.

screen shot 2016-10-30 at 13 49 16

Although I tried to set the values, I could not found the static properties named TraceConfiguration.DisplayErrroTraces or the method named environment#Tracing.
I guess this features are no longer available in the Nancy 2.0, right?

I noticed a few minutes later, that the following code works.

    public class Bootstrapper : Nancy.DefaultNancyBootstrapper 
    {
        public override void Configure(INancyEnvironment environment)
        {
            var config = new Nancy.TraceConfiguration(enabled: false, displayErrorTraces: true);
            environment.AddValue(config);
        }
    }

I think it is better to show the example like above, How do you think?

Most helpful comment

Right, I was missing a using directive, full class for other people in case they have the same problem:

using Nancy;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
using Nancy.Configuration;

public class CustomBootstrapper : DefaultNancyBootstrapper
{
        public override void Configure(INancyEnvironment environment)
        {
            environment.Tracing(enabled: false, displayErrorTraces: true);
        }
}

Thank you!

All 5 comments

Hi,

Thanks for letting us know. I think the error message it pretty straight forward, especially the sentence is very explicit about what to do

  1. Override the Boostrapper's Configure method
  2. call environment.Tracing(enabled: false, displayErrorTraces: true)

So for the time being we'll not be making any changes

I find this confusing too, didn't find a way to enable these on the documentation, and using the class from miyatin shows this error:

error CS0234: The type or namespace name 'INancyEnvironment' does not exist in the namespace 'Nancy' (are you missing an assembly reference?)
error CS0115: 'CustomBootstrapper.Configure(INancyEnvironment)': no suitable method found to override

If you're using v2 follow the instructions in the error page. In a bootstrapper override Configure and use environment.Tracing

Right, I was missing a using directive, full class for other people in case they have the same problem:

using Nancy;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
using Nancy.Configuration;

public class CustomBootstrapper : DefaultNancyBootstrapper
{
        public override void Configure(INancyEnvironment environment)
        {
            environment.Tracing(enabled: false, displayErrorTraces: true);
        }
}

Thank you!

What level of logging does config change actually provide? :)

    public override void Configure(INancyEnvironment environment)
    {
       environment.Tracing(enabled: false, displayErrorTraces: true);
    }

Yesterday I ran into an issue with the Nancy Bind<> crashing on me with ModelBinding.ModelBindingException which was caused by a bad DateTime field value 0002-01-01 00:00:00 +0000;, and I had kind of hoped that this config would actually tell me what the offending attribute was by name but it didn't.

BTW. Found the bug but I had to resort to writing out several get/set methods on my date fields to find the offending one. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Radzhab picture Radzhab  ·  11Comments

jchannon picture jchannon  ·  7Comments

epsitec picture epsitec  ·  5Comments

cody82 picture cody82  ·  9Comments

RTodorov picture RTodorov  ·  6Comments