Magento developer mode

Activating

This now happens as part of site import, by checking and modifying .htaccess for these Apache web server settings.

It also happens as part of site cloning between servers – so any new sites will have this setting activated.

What does it do ?

The philosophy of developerMode is to make errors clearly visible (and simpler to solve) rather than “hiding them”. Of course, in a live site, you don’t want the product page to break because it references an non-existing variable. But in all other scenarios, it is good if it really shows – the only way to handle them is to fix it then.

The most obvious place developerMode kicks in is inside mageCoreErrorHandler (path: app/code/core/Mage/Core/functions.php). This is the place we we end up in when things that issue warnings and notifications inside PHP engine takes place. Magento simply has to decide “what to do” with the warning. Log it, echo it out, or simply continue execute as if nothing happened?

Magento PHP code from core:

function mageCoreErrorHandler($errno, $errstr, $errfile, $errline){

    // …

    // code removed

    // …

    $errorMessage .= “: {$errstr}  in {$errfile} on line {$errline}”;

    if (Mage::getIsDeveloperMode()) {

        throw new Exception($errorMessage);

    } else {

        Mage::log($errorMessage, Zend_Log::ERR);

    }

}   

So developerMode really decides whether to throw an exception, or whether to silently log it. Also logging is an issue, since on a high traffic site, logging can eat significant disk space if an error is on a frequently rendered page.

Magento checks for developer mod ins some other situations as well, such as when:

  • Calling non existing observer functions declared in etc/config.xml.
  • Printing stack traces for exceptions, in API calls (V2).
  • It forces Magento logging on, even if disabled in admin settings.
  • Redeclaring a layout block with same name as before.
    • This is commented out in later Magento.

Activating – Previous approach

Instead of patching the index.php file for all sites we download, we can set the MAGE_IS_DEVELOPER_MODE environment variable for Apache.

Everyone should do this (only then can we see if this is good or not).

To set this up:

  1. In your MAMP window, switch to the tab called “Hosts” (near top left of window).
  2. Then for all hosts in that list (likely there’s only localhost), click on the host – Advanced – “Customized virtual host general settings”, enter:

 

SetEnv MAGE_IS_DEVELOPER_MODE 1

 

Then click Apply, which will make MAMP restart the servers.

Two issues with the above solution:

1. In Magento 1.3 there was no check for the MAGE_IS_DEVELOPER_MODE environment variable, and instead the developer mode line was commended out. This means the above solution will not work for 1.3 sites.

However, we have enough 1.4 sites that we can test the usefulness of having Developer Mode turned on (using the above method) with those sites.

2. For some reason some sites have the Developer Mode lines commented out in index.php

This must be something we introduced (I checked all original Magento sources), and its not commented out there. We should probably reverse those cases as we find them, to firstly stick as close to the standard code, and secondly to allow the above method to turn on developer mode.

See this obsolete page: settings_in_admin_index.php_for_magento_development

(Just as a side note: I chose the above method, because its way easier than to make sed understand all possible variations of the index.php file, so that it can correctly enable developer mode. So a shortcut really  )

More about Developer mode

http://alanstorm.com/magento_exception_handling_developer_mode

http://alanstorm.com/magento_log_and_developer_mode

Developer mode affect translations

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s