Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added helpful error message when ELMAH SQL objects are missing #492

Closed
wants to merge 1 commit into from

3 participants

@Haacked

When running a clean clone of NuGet gallery, there's a manual configuration step that's required to get ELMAH working.
But the error message ELMAH gives doesn't help much. I added some code so that we present a more helpful message.

ELMAH not configured correctly.
Run the SQL script 'Elmah.SqlServer.sql' located in '{SolutionDir}\packages\elmah.sqlserver.1.2\content\App_Readme\' against your SQL database.
@Haacked Haacked Added helpful error message when ELMAH SQL objects are missing
When running a clean clone of NuGet gallery, there's a manual configuration step that's required to get ELMAH working.
But the error message ELMAH gives doesn't help much. I added some code so that we present a more helpful message.

    ELMAH not configured correctly.
    Run the SQL script 'Elmah.SqlServer.sql' located in '{SolutionDir}\packages\elmah.sqlserver.1.2\content\App_Readme\' against your SQL database.
2f4d19a
@Haacked

Even better might be to have .\Build-Solution.ps1 run the SQL script. But given the script will be at a different location for each version of ELMAH, I decided not to do that at this time because I'm lazy.

@davidfowl
Collaborator
@Haacked

Ah, so it's an embedded resource? I like that. If others agree, I'll do that and send a pull request. I'll have to edit the chapter I'm writing though to remove the part about running the script manually. :P

@Haacked

Also, do you know if that migration fails if someone already manually ran the script?

@davidfowl
Collaborator

I believe it noops (IF NOT EXISTS etc) but I dunno for sure.

@Haacked

I'll double check. This got me thinking though, what if the elmah sql package had a PS script that checked to see if Migrations were enabled, and if so, generated a migration that does this. Too invasive?

@davidfowl
Collaborator

No I like that, I'd prefer if I didn't have to do anything. Or maybe another package that's Elmah.EntityFramework.Migration or something that does what you suggest so people aren't surprised.

@half-ogre

I think doing what Jabbr is doing is a good start. I've been thinking of writing an EF-based ELMAH provider, which would then have actual entities for EF, and the migrations stuff would just be automatic. That, to me, is the proper fix. But, like I said, I'm fine starting with what Jabbr is doing.

@half-ogre

So, shall I pull this in until we do something smarter?

@davidfowl
Collaborator

Weren't we just going to copy the migration from jabbr?

@davidfowl
Collaborator

Weren't we just going to copy the migration from jabbr?

@half-ogre

Fixed with fa70cef

@half-ogre half-ogre closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 29, 2012
  1. @Haacked

    Added helpful error message when ELMAH SQL objects are missing

    Haacked authored
    When running a clean clone of NuGet gallery, there's a manual configuration step that's required to get ELMAH working.
    But the error message ELMAH gives doesn't help much. I added some code so that we present a more helpful message.
    
        ELMAH not configured correctly.
        Run the SQL script 'Elmah.SqlServer.sql' located in '{SolutionDir}\packages\elmah.sqlserver.1.2\content\App_Readme\' against your SQL database.
This page is out of date. Refresh to see the latest.
View
53 Website/Infrastructure/NuGetErrorLogPageFactory.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Data.SqlClient;
+using System.Web;
+using Elmah;
+
+namespace NuGetGallery.Infrastructure
+{
+ public class NuGetErrorLogPageFactory : ErrorLogPageFactory
+ {
+ public override IHttpHandler GetHandler(HttpContext context, string requestType, string url,
+ string pathTranslated)
+ {
+ return new HttpHandlerWrapper(base.GetHandler(context, requestType, url, pathTranslated));
+ }
+
+ private class HttpHandlerWrapper : IHttpHandler
+ {
+ private readonly IHttpHandler _handler;
+
+ public HttpHandlerWrapper(IHttpHandler handler)
+ {
+ _handler = handler;
+ }
+
+
+ public bool IsReusable
+ {
+ get { return _handler.IsReusable; }
+ }
+
+ public void ProcessRequest(HttpContext context)
+ {
+ try
+ {
+ _handler.ProcessRequest(context);
+ }
+ catch (HttpUnhandledException e)
+ {
+ if (e.InnerException != null && e.InnerException is SqlException &&
+ (e.InnerException.Message.IndexOf("Could not find stored procedure",
+ StringComparison.OrdinalIgnoreCase) > -1))
+ {
+ context.Response.Write("<h1>ELMAH not configured correctly.</h1>");
+ context.Response.Write(
+ @"<p>Run the SQL script '<em>Elmah.SqlServer.sql</em>' located in '<em>{SolutionDir}</em>\packages\elmah.sqlserver.1.2\content\App_Readme\' against your SQL database.</p>");
+ return;
+ }
+ throw;
+ }
+ }
+ }
+ }
+}
View
4 Website/Web.config
@@ -40,7 +40,7 @@
<location path="elmah.axd">
<system.web>
<httpHandlers>
- <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
+ <add verb="POST,GET,HEAD" path="elmah.axd" type="NuGetGallery.Infrastructure.NuGetErrorLogPageFactory, NuGetGallery.Website" />
</httpHandlers>
<authorization>
<allow roles="Admins" />
@@ -49,7 +49,7 @@
</system.web>
<system.webServer>
<handlers>
- <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
+ <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="NuGetGallery.Infrastructure.NuGetErrorLogPageFactory, NuGetGallery.Website" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
View
1  Website/Website.csproj
@@ -213,6 +213,7 @@
<Compile Include="Infrastructure\Jobs\WorkItemCleanupJob.cs" />
<Compile Include="Infrastructure\Jobs\UpdateStatisticsJob.cs" />
<Compile Include="Infrastructure\Lucene\PackageIndexEntity.cs" />
+ <Compile Include="Infrastructure\NuGetErrorLogPageFactory.cs" />
<Compile Include="JsonApiController.generated.cs">
<DependentUpon>T4MVC.tt</DependentUpon>
</Compile>
Something went wrong with that request. Please try again.