3

I'm sorry if this is a bleedingly obvious question. I think I am going crazy.

I have code that I know is stopping at a specific point. The file I am looking at is app/code/core/Mage/Downloadable/Helper/Download.php (NB. yes, I totally understand and agree that I should not be fiddling with core, but this is just my playing around in a locally installed Magento, and going to be reverted back afterwards)

The line that the code is breaking at is:

if (!isset($urlProp['scheme']) || strtolower($urlProp['scheme'] != 'http')) {
    Mage::throwException(Mage::helper('downloadable')->__('Invalid download URL scheme.'));
}

It is not getting past the Mage::throwException line. I know this because I am logging comments (to my own custom log file) before and after that line, and only the comments before that line are being logged.

My question is not why I am getting this specific error for this specific bit of code - but why I am not seeing the Invalid download URL scheme. error ANYWHERE. It is not appearing in my browser when the code is run, and it is not appearing in exception.log (that file actually does not exist in var/log - nor does system.log). Am I right in thinking that I should be seeing that error somewhere? It is making debugging very difficult!

Here's what I've done to try and get errors showing:

  1. In System/Configuration/Advanced/Developer/Log Settings - Set "Enabled" to "Yes".
  2. In index.php, I have got Mage::setIsDeveloperMode(true);
  3. In index.php, I have got ini_set('display_errors', 1); I know this is working because if I force a syntax error, I get an error in browser.
  4. In /errors, I have renamed local.xml.sample to local.xml (not sure what this one does but have seen it in a couple of articles to do with exception printing).
  5. I have checked that var/log is writable. I know this is working because there is another custom log file that I am writing to successfully with Mage::log

Any ideas greatly welcomed! What should Mage::throwException actually be doing - printing in browser, or in exception.log, or both?

I am using Magento CE 1.9.0.1 on localhost (using a Mac with MAMP).

3
  • Do you have anything in your server's error logs as opposed to the Magento logs? Nov 18, 2014 at 23:16
  • I've just looked and I've got the following in Applications/MAMP/logs/apache_error.log "[Tue Nov 18 23:05:23 2014] [error] [client 127.0.0.1] client denied by server configuration: /Applications/MAMP/htdocs/magento-playpen/app/etc/local.xml" This isn't being logged every time I run the code though. Logs in php_errors don't seem to be relevant (just logs for syntax errors I was forcing during testing).
    – Sarah
    Nov 18, 2014 at 23:23
  • The message about app/etc/local.xml is actually nothing bad. Read about it here: stackoverflow.com/questions/4360574/… Nov 18, 2014 at 23:36

1 Answer 1

2

It throws an exception, nothing more, nothing less.

That means, any code higher up the stack may catch it and do whatever it decides to. Typically it's one or more of the following:

  1. Mage::logException() (this is where it gets added to exception.log)
  2. show an error message to the user
  3. just move on
  4. throw another exception

My guess is on (3) in your case. Get a debugger installed on your development system, set a breakpoint at the Mage::throwException() line and you will find out. And I actually highly recommend looking at the core. It's one of the best resources to learn Magento development.

Update:

if you see a page with something like "An error occured, please contact the store owner" and a long number, this is what Magento shows you for uncaught exceptions. You will find the exception message and stack trace logged in var/report/HERE_COMES_THE_NUMBER

6
  • Thanks for your reply. The thing is, even if I add Mage::logException('Invalid download URL scheme'); above the Mage::throwException line, I'm still not getting anything in exception.log! I must admit I am new to a lot of this so I am not really sure what you mean by 'Get a debugger installed' or 'set a breakpoint' but I will have to do some research about how I can set this up in MAMP! Thanks.
    – Sarah
    Nov 19, 2014 at 0:01
  • Further to what you said, this specific code is actually a few functions deep, and I can see there is a try/catch statement a few levels up, in the DownloadController (which calls this function within some other functions), which is throwing the error that I am getting "An error occured... Please contact the store owner". But I want to see the more detailed errors from the deeper functions!
    – Sarah
    Nov 19, 2014 at 0:05
  • @Debugger: I recommend xdebug.org which works nicely together with IDEs like Netbeans, Eclipse PDT or PHPStorm. However, if you write your code in notepad, it's going to be difficult ;) Nov 19, 2014 at 0:09
  • @Mage::logException(...): the method requires an actual exception object as parameter, not just a string. So what you tried, results in a different error. Nov 19, 2014 at 0:10
  • Thank you for the pointers! I have at least got errors logging to exception.log now, passing the exception object from DownloadController - progress at last. It just strikes me as kind of odd that anyone throwing an exception would not want it to be logged somewhere, if you had logging turned on, but I guess that is because I am new to learning all this and am not clear on the full picture.
    – Sarah
    Nov 19, 2014 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.