I have installed the sfErrorNotifierPlugin. When both options reportErrors/reportPHPErrors reportPHPWarnings/reportWarnings are set to false, everything is ok. But I want to catch PHP exceptions and warnings to receive E-mails, but then all my tasks fail, including clear-cache. After few hours of tests I'm 100% sure that the problem is with set_exception_handler/set_error_handler.
There's a similar question:
sfErrorNotifierPlugin on symfony task but the author there is having problems with a custom task. In my case, even built-in tasks fail.
I haven't used sfErrorNotifierPlugin, but I have run into 'The “default” context does not exist.' messages before. It happens when a call is made to sfContext::getInstance() and the context simply doesn't exist. I've had this happen a lot from within custom tasks. One solution is to add sfContext::createInstance() before the call to sfContext::getInstance(). This will ensure that a context exists.
There's an interesting blog post on 'Why sfContext::getInstance() is bad' that goes into more detail - http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/
Well, the problem could not be solved this way, unfortunately. Using sfErrorNotifierPlugin, I have enabled reporting PHP warning/errors (apart from symfony exceptions) and this resulted in huge problems, e.g. built-in tasks such as clear-cache failed.
The solution I chose was to load the plugin only in non-task mode (project configuration class):
public function setup()
{
$this->enableAllPluginsExcept('sfPropelPlugin');
if ('cli' == php_sapi_name()) $this->disablePlugins('sfErrorNotifierPlugin');
}
WHen a task is executed, everything works normally. When an app is fired from the browser, emails are sent when exception/warning occurs (maybe someone will find it useful).
Arms has explained the problem correctly. But usually context does not exist when executing backend/maintenance tasks on the console. And it is easier if you handle the condition yourself.
Check, if you really need the context?
If you do, what exactly do you need it for?
Sometimes you only want a user to populate a created_by field. You can work around by hard-coding a user ID.
If you want to do something more integrated, create a page (which will have a context) and trigger the task from there.
you can test the existance of the instance before doing something inside a class. Like:
if(sfContext::hasInstance())
$this->microsite_id = sfContext::getInstance()->getUser()->getAttribute('active_microsite');
I've been experiencing the same problem using the plugin sfErrorNotifier.
In my specific case, I noticed a warning was raised:
Warning: ob_start(): function '' not found or invalid function name in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
Notice: ob_start(): failed to create buffer in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
So, checking the file: sfApplicationConfiguration.class.php class, line 155,
I've replaced the ' ' for a null, then the warnings disappears, and also the error!
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : ''); bad
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null); good
Related
In using realbrowserlocusts class it appears that I'm limited in any exception handling.
The only reference that partially works is: self.client.wait.until(EC.visibility_of_element_located ....
In a failed condition where the element is not found the script simply starts over again. With the script I'm working with I need to maintain a solid session state; I need to throw and exception(report an error), log the user out and then let the script start over again. I've been testing out the behavior with the locust.py script that Nick B. created with several approaches to "try, except" and they work running without realbrowserlocusts (selenium only) but with it the execution just stops.
Any examples would be greatly appreciated.
In its current format I've been able to run 3x the amount of a browser-based load per/agent/slave than our commercial tool. My goal is to replace it with a locust/selenium approach.
locust-plugins's WebdriverUser has a little bit better exception handling I think. A failure to find an element will log a failed request and if you use RescheduleTaskOnFail (as in the the example) it will restart the task when that happens.
https://github.com/SvenskaSpel/locust-plugins/blob/master/examples/webdriver_ex.py
I am trying to show an array of TPANELs to be used by the user as a menu system. It all seems to work fine but here's the issue.
If I always click the first item (i.e., TPanel), then I can click the other items as well. But if I start by clicking the last item, it shows the error "Access violation" AFTER it has shown the items.
The strange thing is that despite the error, the system does not crash. So I enabled the debugger (DBG). Now it crashes with the error as follows:
And once the program stops, I see the following in the history window of the debugger.
Please note that I'm not keen right now in fixing this error as I think this is trivial. But I want to be able to capture the error as it occurs and do something (for now I want to ignore it).
I'm using Ubuntu 12.04 with Lazarus 1.0.10.
The method I use must work on WINDOWS and LINUX.
Thanks in advance for any help!
Generally, to catch an exception, there's the try..except block. For sure your goal is not to catch an exception and ignore it, but find it in your code and fix the source of the problem. Of course, there might be situations, where the risk of an exception is high or expected so the use of a try..except block is necessary there. Those blocks of code we are enclosing this way:
procedure TForm1.Button1Click(Sender: TObject);
var
NotExistingPanel: TPanel;
begin
try
NotExistingPanel.Caption := ''; // <- this will raise an access violation
except
on E: Exception do
ShowMessage('An exception was raised: ' + E.Message);
end;
end;
Your problem will be somewhere in an OnMouseUp event handler of some of your controls and it's been caused by accessing the memory, that the CPU cannot physically address. This might happen e.g. when you access an object which has not been created, or already released, but there are also many different ways how to cause an access violation.
First, a big thank you to TLama for all the explanations and directions. I have to accept his answer as I've built mine based on that. I'm only posting this as an answer so that another person who's a beginner to Lazarus may find this useful. I'm not in anyway suggesting that this is the best thing to do, but this is what I want to do for now. That is, when a certain exception occurs, I want to trap it and deal with it.
Given that,
I am dynamically creating a set of TPanels to look like buttons
Each TPanel has assigned to it a mouseclick event
Let's assume that there are 10 such 'buttons' (actually TPanels).
The problem:
When I first click on the first button, I can then click on another one (eg: the 5th). But if I first click the 5th or anything else other than the first, the program throws the 'Access violation' error. Note however, that the program doe not crash despite the ugly warning about data corruption and stuff. So the user can simply click ok and continue. Strangely then, with subsequent clicks, this problem reduces! I know that's funny.
Now, as explained by TLama, the error occurs when the mouse is being released AFTER clicking a button.
But here's my problem... I don't have a mouseup event. That's part of Pascal.
So now, I want to ignore the mouseup event (at least for now). There MUST be a better way.
But there's another issue. I cannot ignore what I don't have! And I don't have a mouseup event. So I finally decided to capture this error at application level like this:
On the main form, I put this code:
procedure TfrmMainForm.CatchErr(Sender: TObject; e:exception);
begin
if e.Message <> 'Access violation' then ShowMessage('MOL: ' + e.Message);
end;
And then on form create, I put this:
Application.OnException:=#CatchErr;
And (for now) I can circumvent this issue.
Once again, as TLama has indicated, this is not good advice. Nonetheless, it is what I wanted to do.
Also what makes it harder is that the error is occuring in mouseup, which is in control.inc. And this is not my file. Rather it's part of Lazarus. I think it would be better if we had a way of telling Lazarus to delete that event for the TPanels in the code. I think it involves re-writing a derived class for it and I don't see how that's any good for me right now :)
Thanks again TLama!
I had a non-OSGi application. To convert it to OSGi, I first bundled it up and gave it a simple BundleActivator. The activator's start() started up a thread of what used to be the main() of my app (and is now a Runnable), and remembered that thread. The activator's stop() interrupted that thread, and waited for it to end (via join()), then returned. This all seemed to be working fine.
As a next step in the OSGiification process, I am now trying to use OSGi configuration management instead of the Properties-based configuration that the application used to use. So I am adding in a ManagedService in addition to the Activator.
But it's no longer clear to me how I am supposed to start and stop my application; examples that I've seen are only serving to confuse me. Specifically, here:
http://felix.apache.org/site/apache-felix-config-admin.html
They no longer seem to do any real starting of the application in BundleActivator.start(). Instead, they just register a ManagedService to receive configuration. So I'm guessing maybe I start up the app's main thread when I receive configuration, in the ManagedService? They don't show it - the ManagedService's updated() just has vague comments saying to "apply configuration from config admin" when it is passed a non-null Dictionary.
So then I look here:
http://blog.osgi.org/2010/06/how-to-use-config-admin.html
In there, it seems like maybe they're doing what I guessed. They seem to have moved the actual app from BundleActivator to ManagedService, and are dealing with starting it when updated() receives non-null configuration, stopping it first if it's already started.
But now what about when the BundleActivator's stop() gets called?
Back on the first example page that I mentioned above, they unregister the ManagedService. On the second example page, they don't show what they do.
So I'm guessing maybe unregistering the ManagedService will cause null configuration to be sent to ManagedService.updated(), at which point I can interrupte the app thread, wait for it to end, and then return?
I suspect that I'm thoroughly incorrect, but I don't know what the "real" way to do this is. Thanks in advance for any help.
BundleActivator (BA) and ManagedService (MS) are callbacks to your bundle. BundleActivator is for the active state of your bundle. BA.start is when you bundle is being started and BA.stop is when it is being stopped. MS is called to provide your bundle a configuration, if there is one, or notify you there is no configuration.
So in BA.start, you register your MS service and return. When MS is called (on some other thread), you will either receive your configuration or be told there is no configuration and you can act accordingly (start app, etc.)
Your MS can also be called at anytime to advice of the modification or deletion of your configuration and you should act accordingly (i.e. adjust your app behavior).
When you are called at BA.stop, you need to stop your app. You can unregister the MS or let the framework do it for you as part of normal bundle stop processing.
I have to modify an Oracle Form but cannot find my way to start.
What is the start up order for a standard form? That is which event, trigger etc will be called at form load, canvas load, etc. I assume that it is When-New-form-Instance but a cannot get it to stop at a break point on the first line of this trigger.
I am getting
FRM-40735 ON_ERROR trigger raised unhandled exception ORA-06508
Which I suspect means I do not have my environment set up correctly but I have done the same as others at this site. So I thought to start with debugging and try to identify which call is failing
PRE-FORM fires before WHEN-NEW-FORM-INSTANCE. Check what's defined in PRE-FORM trigger.
Also, your ON-ERROR trigger is giving a ORA-06508 error, so might want to check what program unit is being referred to in the ON-ERROR trigger
To get a start in trying to find the source of the error, try disabling custom code in forms. If the error does not persist when custom code is disabled, you'll have to start tracing through CUSTOM.PLL to find the source of the issue.
Alright dudes... I have a problem that is looking for an answer more specific than the seemingly obvious solution.
I have a block of code that I want to execute directly after a url is known to be valid. What I mean by 'valid' is that the program has checked to see if that filepath actually exists. This could be accomplished by a COMPLETE listener, because after all, a loader couldn't finish loading its content if the referenced file didn't exist, but I want it to happen before any of the bytes begin to get sucked in. I have also tried the HTTPS_STATUS event, with a conditional saying "if the status is this [some non-error status number], then run this block of code." This would have worked great, except that different environments produce different network codes, and some even can't distinguish between errors and non-errors, just returning 0's no matter what. Because of this, I can't write a conditional that works no matter what browser....
So, anyone got any ideas?!?!?!?!
If this doesn't work post your code.
myUrlLoader.addEventListener(Event.OPEN, openHandler);
//Dispatched when the download operation commences following a call to the URLLoader.load() method.