I'm using Elmah in a WebForms app and would like the ability to alter an exception before Elmah logs it. In my scenario there are exceptions being thrown by some of my dependency components that have many custom InnerExceptions with details that Elmah ignores. So I'd like the opportunity to iterate the InnerExceptions and add textual details to the main exception just before Elmah logs it.
I can see how I would filter exceptions entirely, but it doesn't look like I could alter the exception and still allow it to be logged. Any ideas?
Could you handle your exceptions instead of leaving them unhandled for ELMAH to pick up automatically, and raise a custom exception with some property that ELMAH reads overridden to display what you want from your custom exception properties? e.g. Message
ErrorSignal.FromCurrentContext().Raise(...)
We addressed this by forking Elmah locally and adding code to iterate over the exceptions as per the suggestions in this Elmah issue:
http://code.google.com/p/elmah/issues/detail?id=162&can=1&q=data
Building our own version also allowed us to add a couple of other things that the current version of Elmah doesn't provide out of the box.
As an aside the next version of Elmah is in development - there seem to be substantial changes to a least some of the codebase - so I'll need to revisit this problem and our other additional logging requirements once it gets to release.
Related
Often GCP Error Reporting's groupings are helpful in making the tool coherent and allowing for quick identification of issues; however, sometimes I would like to make sure that Error Reporting creates a separate group for a specific error and does not group it together, for instance the failure of a system. Is it possible, through the ErrorReporting Node.js client (we are using Node.js Cloud Functions) or otherwise to force-create an Error and ensure that it is not grouped with other, similar stack traces?
Error reporting are grouped by following these general patterns:
Exceptions are grouped together if they have the same exception type and similar stacks.
The stack trace is ignored for exceptions that are typically unrelated to the source location where they occur.
Errors without an exception stack are grouped together if they were created by the same log statement, approximated by the source location it was reported from (reportLocation).
You can also create a custom error reporting for Node.js by using the client library. Refer to this guide in setting up error reporting for Node.js
The django docs clearly states
You shouldn't alter settings in your applications at runtime.
Here's the link to that statement
My question is, why is this so? I want to add applications dynamically at runtime, and add databases at runtime, both of which involve editing the settings. Can someone explain why settings are not to be edited at runtime and if exceptions exist, which settings they are and why they are exceptional? I'm not so much interested in how to achieve my goal, but in the reason for why settings shouldn't be altered.
Most settings will not be re-read if you change them at runtime. So Django will not recognise the changes you make.
This is due to the fact that Django is just normal Python code. It isn't like a server that is monitoring your code - it is just part of your code.
In some cases, parts of Django code might respond to changes in settings, because they might do 'settings.DEFAULT_FROM_EMAIL' every time mail is sent, for example.
But if Django processes the setting in any way, like it has to do for INSTALLED_APPS, it isn't going to notice you changed something and re-do the processing.
Which settings are safe? Well, the docs are saying "none are safe", because it might change in the future. Django might save a copy of any setting for some reason, or do some processing.
Changing INSTALLED_APPS could never be made to work, because it alters which modules are imported. There is simply no way that Django could work around the way that Python works at this level - it would need to be able to 'unimport' modules, which is basically impossible (the only way is to restart the process), and there are other problems associated with cross-app links.
AFAIK there is no documentation on which settings are safely modifiable at runtime, but there is an open ticket asking that they be documented more clearly.
If you take a look under the hood at the settings object Django exposes to interface with your project's settings module, you'll notice that there's nothing preventing you to dynamically change the settings at runtime.
You should, however, appreciate that the framework's architecture is built around a request-response flow where a lot of global state is being shared between threads for memory optimization, based on the premise that the application is configured only once during initialization.
I am looking for a good ldap library on Django, that would allow me to manage my ldap server :
adding, modifying, deleting entries
for groups, users, and all kind of objects
The library django-ldapdb looked promising, it offers a Model base class that can be used to declare ldap objects in a Django fashion (which is what we ideally want), however we've had some bugs with it, and furthermore it seems like it is not maintained any more.
Does somebody know a good library that could do the trick ? Otherwise I guess I'll just try to improve and debug django-ldapdb ...
Thanks !
sebpiq, you say you applied "one or two fixes" to django-ldapdb, would you care to share them? So far django-ldapdb meets my needs, but I'd be happy to integrate any fixes you might have.
When using ldapdb to query ldap with more results than the server allows instead of getting the partial list (of say the first 500 users) I get SIZELIMIT_EXCEEDED exception. Trying to change the code to catch that exception resulted in an empty result objects.
Anyone else had that problem?
I fixed that problem by changing the search_s function to use search_ext and read the results one by one until the exception happens.
http://www.python-ldap.org/doc/html/index.html
The beauty of Django is that you can use any python module within your application.
There is also django-auth-ldap which claims
LDAP configuration can be as simple as a single distinguished name template, but there are many rich options for working with User objects, groups, and permissions.
Actually, I have found out that with one or two fixes, django-ldapdb is a pretty good library. The only bad point is that it is not very actively maintained... I will use it anyways, because it is the best solution I have found.
I’m using SharpArch with SharpArch.Contrib’s [Transaction] attribute. The Transaction attribute is added to an application service method and if an exception is thrown during that method then any changes to any domain objects are rolledback. From all appearances this works well.
However, I’m writing NUnit tests to confirm that exceptions are being thrown when appropriate (invalid state, security errors, etc) but I also want to confirm that the Transaction attribute is present and doing its job to rollback the changes. Is there any way I can do this?
I do trust that SharpArch.Contrib’s Transaction attribute is solid code, but some future programmer could accidentally remove the Transaction attribute from a method or disable it during testing which would not be caught by the unit tests. Am I being overly cautious?
Thanks
Dan
I think you're being a little paranoid, but that's OK :-)
If you trust the SharpArch code, then I wouldn't worry about the exception being thrown back to you correctly. Assume that it works and pick up any problems during integration or functional testing. Testing third party code only has value when you either don't trust it or you're trying to understand it.
On the other hand if you want to test for the presence of an attribute (i.e. validate that the method has the appropriate attribute on it) then you can write a test that uses reflection to inspect the method signature and do some assertions. It's not too hard to do - you just use the methodinfo object to work out the attributes on the method and scan for the TransactionAttribute.
I think testing the transactionality of your code makes perfect sense. I would do it on integration level, when you connect to the real database - then it is easy to generate wrong data, catch the exception and assert that there were no changes done in the database.
I am not sure how you would test it on a unit test level.
I am getting an Interface Error/ Operational Error while running my Django application with FastCGI.On checking the access log ( of lighttpd) i find these errors pop up which are usually related to closing some db connection or the other.
The browser displays one of the two things - Unhandled Exception or Connection Terminated unsuccessfully message. Upon refreshing the page once ( usually) the errors seem to go off.
How can I prevent this from happening ? The system really behaves in an erratic fashion.
There could be 2 reasons for this problem occuring.
1. Not all URLs mentioned in your urls.py are reversing properly.
2. This is the tough part - Somewhere in the project an import is failing. It may be importing a method which does not exist.
I faced the same problem and I discovered that there were many imports like the ones mentioned in the second point.
I faced the same problem, and wrote my own solution after finding nothing from the web. Please check my blogpost here: Simple Python Utility to check all Imports in your project
Ofcourse this will only help you to get to the solution of the original issue pretty quickly and not the actual solution for your problem by itself.