Codeigniter hiding errors from libraries. Why? - codeigniter

So I has a small problem as I outlined here.
I have made a new question because this is more general and will perhaps help others.
So essentially, I integrated the Facebook SDK Into Codeigniter as a library.
The SDK requires Json and Curl.
In the base_facebook.php file there is the following code:
if (!function_exists('curl_init')) {
throw new Exception('Facebook needs the CURL PHP extension.');
}
if (!function_exists('json_decode')) {
throw new Exception('Facebook needs the JSON PHP extension.');
}
If these functions are not available I expect an error to be fired to tell me such. Then I can install the correct packages and continue.
What actually happened is that even when I had error reporting set to E_ALL a blank page was returned.
This made it impossible to debug and after lots of playing I worked out it was because CURL was not installed on my server.
My question is why does codeigniter show blank pages rather than library based exceptions?
Furthermore even if there is an exception in a library why does the rest of the page not continue executing.
Essentially CI is seemingly making the use of exceptions worthless..
COuld anyone advise?
THanks

My question is why does codeigniter show blank pages rather than library based exceptions?
Most likely because display_errors is set to “off”.
While this is recommended for a production environment (web site users are not supposed to see internal error messages – it might give them info about internals, that they are not supposed to have) – it’s not very helpful while developing, where you as the developer want to be informed about what went wrong.
So check if CI has a “debug” setting for this, or if it’s maybe already set to off in your PHP configuration.
(Maybe CI or your config are set up in a way that errors are logged to a file instead. Also recommended for production; while developing, you’d have to keep an eye on this file then.)
Furthermore even if there is an exception in a library why does the rest of the page not continue executing.
Because that’s how exceptions are supposed to work – if they are not being caught when they reach the “top level” of your app, they cause a fatal error, and scripts die when those occur.
Familiarize yourself with the concept of try { … } catch(…) { … } to handle exceptions that might occur in script flow.
(Actually, it’s kinda surprising you don’t know all this already, if you’re working with an advanced PHP framework …)

Related

How should I handle serious errors in Vue components within Laravel apps?

[Clarified]
I'm writing my first Laravel app using Vue components; it is a CRUD. I know how to report significant problems to laravel.log via the Log::error("There is an error") technique but that's only useful while I'm in the PHP code; as far as I can figure out, there's no way to write to laravel.log from within a Vue component. (Correct me if I'm wrong!!)
This raises the question of how I should report an error in a Vue component in a Laravel app. I know about console.log(), Debugger for Chrome, and Devtools and those are fine for development. But what about errors that might reasonably happen in production? Clearly, user errors like bad input on a form needs to be dealt with by notifying the user and letting the user correct their input but some errors are beyond the user's scope. For example, it's not hard to imagine my Vue component failing to access the database because it is down for some reason. Shouldn't that kind of problem be written to a log so that whoever monitors production apps can deal with it?
How would a professional app deal with that kind of situation?
My initial inclination is just to write it to laravel.log if possible but that may be either impossible or be considered a bad approach. I'd be curious to know what experienced Laravel developers do in such situations. Maybe automatically sending a text to a support person would be a better approach. I'm really not sure how this should be handled in a modern professional way.
In any case, whoever is responsible for situations beyond the user's control needs to be told somehow so they can begin the steps that would be necessary to fix the problem. Furthermore, this person needs to be given sufficient details of what happened to be able to solve the problem. I expect that would include things like stacktraces, error codes, etc. I wouldn't want to send all of that as a stream of texts, I'd want it all to be accessible in a log of some kind. Then, you simply notify the support person that there is a problem of such-and-such severity which occurred at such-and-such a time and remind them where to find the details.
My approach may be dated though and newer, better alternatives may exist. Those are what I'm looking for with my question.
I can give a general purpose answer for your question.
React introduced the concept of ErrorBoundary,
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed.
Using Error Boundary in Vue
use vue-error-boundary
This simple code of handleError method shows ErrorBoundary receiving a callback function through the on-error prop.
<template>
<ErrorBoundary :on-error="handleError">...</ErrorBoundary>
<template>
<script>
// ...
methods: {
handleError (err, vm, info) {
// do something
}
}
// ...
</script>
read the docs for the npm module to know more.
while handling errors, you can pass the errors to a link to your production site.
eg. /logging so it would be like https://www.example.com/logging, and post the errors in a format eg Date: Error File: Error Message.
You can even use authentication tokens along this link (though no one would use it as it would be frontend errors everyone can see it at console).
Then use routes to log those errors to laravel logs.

can you replace all errors on codeigniter with my own standard text

Might be a stupid question but hopefully not.
I'm due to launch my site in the next couple of days, and I am worried that there may be a couple bugs about, i've done the best to exterminate them but there may eventually be a couple that slip through the net, that i aint aware about.
I am wondering if it is possible, when an error does appear in codeigniter, instead of specifically saying what the error i can just set some text to be displayed like
"Error found, this has been sent to the website admin"
If you are using CodeIgniter 3, the error pages will be in application/views/errors/. There's different pages for database error, exception errors, php errors, and so on. You can remove the error message from these files and customize the page in any way you'd like. So for the errors/html/error_db, you'd just remove the line with <?php echo $message; ?>.
You can also disable displaying errors by setting the ENVIRONMENT constant to production and enable logging by changing the log_threshold in application/config/config.php.

How can I log javascript errors with Poltergeist/Capybara/Rspec?

I'm using Rspec/Capybara with Poltergeist as a driver to write tests for some large web applications.
My issue is that I would like to record the messages that appear on the console, but so far I've been unable to do so.
I am aware of the options js_errors and phantomjs_logger, but I have had some issues with them:
if I set js_errors: false, the file I specify in phantomjs_logger stays empty;
if I set js_errors: true, console.log messages are logged in the file specified in phantomjs_logger, but then almost all my specs fail because of
javascript errors that may not even be relevant to the navigation example I'm testing.
Any idea on how I can save the console messages while not breaking specs on every js error?
CLARIFICATION:
I have no control over the development, my task is to check the stability of the whole stack of the applications in the various environments, accessing from the front-end, so clearing out all the javascript errors is out of the question. The specs I'm writing are also supposed to ignore javascript errors if they don't impair the usage of the interface.
You can't. The PhantomJS client catches javascript error messages and adds them to an array. Then when a command completes, if js_errors == true, that array is checked and if not empty the javascript errors are returned and trigger an error in the test. There is no other API in poltergeist for accessing those errors. It sounds like you need to have a discussion with your manager about the wisdom of just ignoring JS errors if they apparently don't impair usage - it's a potentially dangerous development practice

Laravel 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' how to find the URL that is causing the issue?

I have a CMS which uses quite a large number of ajax calls. There are no visible issues, but often when I look in Laravel's log file, I see a similar rambling mess of an error message about a 'NotFoundHttpException', presumably due to one of my api calls not finding the correct route.
I love Laravel, but my god, this has got to be one of the most unhelpful errors I have ever seen. There are references there to files deep within Laravel's core which I have no reason to ever touch nor care about. If this is a routing problem (which it ostensibly is) then all I really want to know is what the URL is that is causing the problem.
Is there any way of finding out which is the problem route, or any way of re-configuring the error reporting to tell you?
Thanks.
I don't know of any way to configure Laravel's error logging in such a way, but you can do it by yourself.
The error logging happens in app/start/global.php. There you have the "Application Error Handler". You can easily add an if statement and log your own message, including the actual URL that has been called.
App::error(function(Exception $exception, $code)
{
$message = $exception;
if($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException){
$message = 'URL '.Request::url().' not found - '.$exception;
}
Log::error($message);
});

Facebook Application - Url-rewriting with fbml?

I have an app that I'm creating with CakePHP, which rewrites the url from something illegible to most users to something a little easier to comprehend. I'm having a problem when I use the FBML canvas.
When I try to access, say, http://apps.facebook.com/myapp/articles, I get the following error:
Received HTTP error code 404 while
loading
http://www.myapp.com/myapparticles/
I did notice that when I try to access http://apps.facebook.com/myapp/articles/posts, it changes the error to show the following url, which is slightly different: http://www.myapp.com/myapparticles/posts
Which lead me to try accessing it with this: http://apps.facebook.com/myapp//articles, which does work most of the time, though for some reason sometimes it will give the previous error. (And it also seems like a hack-y way of getting it to work).
I'm at a loss for how to fix this.
Turns out I was missing the trailing slash (http://www.myapp.com/myapp/) on the url that I specified as my canvas callback, which is in the app settings. Putting it there fixes the problem.
This happens when you are not using semantic markup or you have an error or some code not supported by fb. Also that famous error is generated by fb when it is down or slow too.
I would suggest you checking your code thoroughly and going through fb documentation. That should help you the most. thanks

Resources