Tracy debugger: No output with ajax exceptions - nette

Whenever I make an ajax request that throws an exception, the Tracy debugger is killing all output.
I've tested with Tracy turned off and exceptions get output. I've tested with just a page (ie: not ajax) and the exception gets output by Tracy properly.
I believe I've traced the problem to Bluescreen::render():
public function render($exception)
{
if (Helpers::isAjax() && session_status() === PHP_SESSION_ACTIVE) {
echo $exception->getMessage();
ob_start(function () {});
$this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/content.phtml');
$contentId = $_SERVER['HTTP_X_TRACY_AJAX'];
$_SESSION['_tracy']['bluescreen'][$contentId] = ['content' => ob_get_clean(), 'dumps' => Dumper::fetchLiveData(), 'time' => time()];
} else {
$this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/page.phtml');
}
}
I added the echo line at the top. It gets output.
The reason I'm asking on SO and not filing a bug report, is because just this morning it was working - the exception text was output, followed by a backtrace, followed by a message saying "unable to log error...". So I'm fairly certain the problem is mine, but I can't figure out where.
I have deleted my copy of Tracy and re-pulled from GitHub, so I'm using the latest & greatest version.

Related

wordpress buddypress white screen of death

I just got a job of maintaining a wordpress/buddypress site.
I install the site locally with a virtual host, so that I didn't change any cfgs or code.
The site was running ok but today morning when I tries to load it I got white screen without any error in the log or anywhere.
I use a debugger to trace the problem and found the following supper-impressive code (wp-content/plugins/events-and-bookings/lib/class_wd_wpmu_oauth.php:378):
private function _refresh_token ($token) {
$this->set_parameter('refresh_token', $token, self::SCOPE_REFRESH);
$this->set_header('method', 'POST');
$raw_token = $this->_refresh_authentication_code();
if (!$raw_token) die;
$token_data = json_decode($raw_token, true);
if (!$token_data) die;
$token_data['time'] = time();
if (!isset($token_data['refresh_token'])) $token_data['refresh_token'] = $token;
$this->set_data('token_data', $token_data);
return $token_data;
}
I comment out the 2 lines that ends with die; - and WALLA! problem solved.
My questions are:
Why does the code die with out any warning - is it a security thing?
is there a better solution than commenting out these lines?
did the change I did can cause some unexpected problem that I'm unaware of?
what is that code actually doing or any info/reference to this problem.
thanks

phpunit test passes, page load in browser fails in Symfony 2

I am new to phpunit testing and did a very simple test looking for status code.
The test passes when I run:
bin\phpunit -c app src\AppBundle\Tests\Controller\StarLinX\TravelControllerTest.php
PHPUnit 4.6.10 by Sebastian Bergmann and contributors.
Configuration read from C:\PhpstormProjects\dir\app\phpunit.xml.dist
.
Time: 6.03 seconds, Memory: 20.00Mb
OK (1 test, 1 assertion)
But when I load the page in the browser, an exception is thrown rendering the twig file with status code 500.
I thought maybe this was a cache issue, so I cleared cache in --env=dev, prod and test.
How do I troubleshoot this error?
This is my test file:
namespace AppBundle\Tests\Controller\StarLinX;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TravelControllerTest extends WebTestCase {
public function testGET() {
// Create a new client to browse the application
$client = static::createClient();
// get the page
$crawler = $client->request('GET', '/travel/aaaaa');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /travel/aaaaa");
}
}
This is the error that is thrown when running in the dev environment:
An exception has been thrown during the rendering of a template ("Notice: Array to string conversion")
So after a little more analysis, I find that the error around {{ weatherInfo }} which should be {{ weatherInfo.now }}. This throws an error when running the development environment. In production, twig simply displays Array.
Is that normal behavior?
As it's written your test only check the error status, the test is not specific enough. What if it displayed another page? The test would still pass.
You should add some other tests in order to ensure that the page is properly displayed:
// …
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
"Unexpected HTTP status code for GET /travel/aaaaa");
// Check that the page has a title.
$this->assertSame(
1,
$crawler->filter('title')->count()
);
// Check that the page has a correct title.
$this->assertSame(
'Travel',
$crawler->filter('title')->text()
);
// Check something in the content
$this->assertSame(
'Hello, World!',
$crawler->filter('body > div#content')->text()
);
If you don't have enough information to debug your code, tou can access to the page content which usually contain the error message:
die($this->client->getResponse()->getContent());

Supress Error messages in Symfony/Twig?

How can I suppress error messages in a symfony controller / swift message, e.g. if the email of the user doesn't exist, something is wrong with the smpt server or the email address simply doesn't comply with RFC 2822.
For example, we got following CRITICAL error...
request.CRITICAL: Swift_RfcComplianceException: Address in mailbox given [ xxx#xxx.com ] does not comply with RFC 2822, 3.6.2. (uncaught exception) at $
... the user then get's a symfony error page "An Error occured" which I need to suppress in any case.
A simple #$this->get('mailer')->send($message); doesn't work here unfortunately ...
protected function generateEmail($name)
{
$user = $this->getDoctrine()
->getRepository('XXX')
->findOneBy(array('name' => $name));
if (!$user) {
exit();
}
else {
$message = \Swift_Message::newInstance()
->setSubject('xxx')
->setFrom(array('xxx#xxx.com' => 'xxx'))
->setTo($user->getEmail())
->setContentType('text/html')
->setBody(
$this->renderView(
'AcmeBundle:Template:mail/confirmed.html.twig'
)
)
;
$this->get('mailer')->send($message);
// a simple #$this->get('mailer')->send($message); doesn't work here
}
return true;
}
To simply suppress the error, wrap the send method in a try-catch block. Choose the exception type wisely. The following example just catches Swift_RfcComplicanceExceptions.
try {
$this->get('mailer')->send($message);
} catch (\Swift_RfcComplianceException $exception) {
// do something like proper error handling or log this error somewhere
}
I'd consider it advisably to apply some validation beforehand, so you can display a nice error to your user.
I'm not sure that a try catch block will work, because mails may be sent later in the request process : http://symfony.com/fr/doc/current/components/http_kernel/introduction.html#l-evenement-kernel-terminate
If you use the framework Full Stack edition, this is the default behavior.
I've also found some refs here : Unable to send e-mail from within custom Symfony2 command but can from elsewhere in app
You can change the Swiftmailer spool strategy in your config to send direct mails...

Meteor: The application is not spiderable

My application is not spiderable both on local and production.
When I go to http://localhost:3000/?_escaped_fragment_=, I can see the following error appears (phantom is killed after 15 seconds):
spiderable: phantomjs failed: { [Error: Command failed: ] killed: true, code: null, signal: 'SIGTERM' }
It seems that many other people got this problem:
https://github.com/gadicc/meteor-phantomjs/issues/1
https://groups.google.com/forum/#!msg/meteor-talk/Lnm9HFs4MgM/YKDMR80fVecJ
https://groups.google.com/forum/#!topic/meteor-talk/7ZbidddRGo4
The thing is I am not using observatory or select2 and all my publications return a cursor. According to me, the problem comes from the minification. I just read in this thread that someone succeed to display "SyntaxError: Parse error". How can I know more about what is going wrong with Phantom and which file is causing the problem?
This happens when spiderable is waiting for subscriptions that fail to return any data and end up timing out, as mentioned in some of the threads you linked.
Make sure that all of your publish functions are either returning a cursor, a (possibly empty) list of cursors, or sending this.ready().
Meteor APM may be useful in determining which publications aren't returning.
If you want to know more about what is wrong with phatomjs, you might try this code (1):
// Put your URL below, no "?_escaped_fragment_=" necessary
var url = "http://your-url.com/";
var page = require('webpage').create();
page.open(url);
setInterval(function() {
var ready = page.evaluate(function () {
if (typeof Meteor !== 'undefined'
&& typeof(Meteor.status) !== 'undefined'
&& Meteor.status().connected) {
Deps.flush();
return DDP._allSubscriptionsReady();
}
return false;
});
if (ready) {
var out = page.content;
out = out.replace(/<script[^>]+>(.|\n|\r)*?<\/script\s*>/ig, '');
out = out.replace('<meta name=\"fragment\" content=\"!\">', '');
console.log(out);
phantom.exit();
}
}, 100);
For use in local, install phantomjs. Then outside your app, create a file phantomtest.js with the code above. And run phantomjs phantomtest.js
Another thing that maybe you can try is to use UglifyJS to catch some errors in the minified JS file as Payner35 did.
My problem was coming from SSL. You can have a complete overview of what I did here.
Edit the spiderable source and add --ignore-ssl-errors=yes to the phantomjs command line, it will work.

Loading Google Maps API with wp_enqueue_script

I'm trying to load the Google Maps API using the following syntax:
add_action('admin_enqueue_scripts', 'load_google_maps');
...
function load_google_maps()
{
// The actual API key is configured in an options page
$key = get_option('google_maps_api_key');
$gmaps_url = 'http://maps.googleapis.com/maps/api/js?key=' . $key . '&sensor=false';
wp_enqueue_script('google-maps', $gmaps_url, NULL, NULL);
}
WordPress is escaping the "&" to "&#038". This actually makes the Google server reject the request. When I type it directly into browser address bar with "&sensor=false" at the end, it loads fine.
I saw a bug of this kind mentioned in the WordPress trac system: http://core.trac.wordpress.org/ticket/9243 but it was dismissed as invalid, and the admin responding to the request showed somehow that the "&#038" approach was fine. It is definitely not fine from Google's point of view.
I could of course just get the function to echo the HTML as a script tag, but I'd rather use the wp_enqueue_script system if possible.
Anyone know of a solution to this?
Cheers,
raff
I've got something similar in our code, and it's working fine (even encoded as &#038). I suspect your problem is that it's being double-encoded, as you already have &. Trying changing it to:
$gmaps_url = 'http://maps.googleapis.com/maps/api/js?key=' . $key . '&sensor=false';
For what it's worth, our (working) code is:
wp_register_script('googlemaps', 'http://maps.googleapis.com/maps/api/js?' . $locale . '&key=' . GOOGLE_MAPS_V3_API_KEY . '&sensor=false', false, '3');
wp_enqueue_script('googlemaps');
($locale in this case is set to hl=en)
Edit
Looks like the behaviour's changed in the latest version of WordPress - the above doesn't work (but I'll leave it for people on legacy versions). The only alternative I can see to echoing the script is to add a clean_url filter, something like this:
add_filter('clean_url', 'so_handle_038', 99, 3);
function so_handle_038($url, $original_url, $_context) {
if (strstr($url, "googleapis.com") !== false) {
$url = str_replace("&", "&", $url); // or $url = $original_url
}
return $url;
}
Pretty ugly, but perhaps marginally better than echoing the script, as it'll still use the WordPress dependency management.

Resources