You’re cruising along, your module has come together. The last step between you and total Magento Connect domination is packaging your extension. You bravely enter System -> Magento Connect -> Package Extension
, and with victory in your grasp …
FAILURE! With no clear path forward, you commit seppuku rather than face continued shame.
There’s a common pattern in older parts of the Magento system where a controller will wrap its business logic calls in a try
block, with two catches. The first
} catch (Mage_Core_Exception $e){
$session->addError($e->getMessage());
$this->_redirect('*/*');
{
looks for a Magento exception. If a Magento exception is thrown, then it’s “safe” to show the user that error message. The second catch
} catch (Exception $e){
$session->addException($e, Mage::helper('connect')->__('Failed to save the package.'));
$this->_redirect('*/*');
}
is for standard PHP exceptions (or Notices, Warnings, etc. if you’re running in developer mode). Here a hard coded string literal is used because it would be best not to show an end user a raw PHP error message.
Of course, we’ve left wondering why our save failed, so this attempt at security and usability ends up being a cruel failure. There’s no elegant way to fix this either. Whenever I run into it when packaging an extension (which is every time I package an extension), I end up temporarily hacking the core with something like this
} catch (Exception $e){
$session->addException($e, Mage::helper('connect')->__('Failed to save the package. '.$e->getMessage()));
$this->_redirect('*/*');
}
This will print out the actual exception message
which is usually enough to track down the problem (in this case I had the wrong target type in the content tab).