welovewordpress / SublimeHtmlTidy

Tidy, clean and prettify your HTML code with this plugin for Sublime Text 2
GNU General Public License v2.0
88 stars 15 forks source link

Error calling script? #2

Closed Fatbat closed 12 years ago

Fatbat commented 12 years ago

Hello. I'm able to get PhpTidy to work, but HtmlTidy is throwing an error for some reason. When I run it it says...

"There was an error calling the script at C:\Users\Myname\AppData\Roaming\Sublime Test 2\Packages/HtmlTidy/tidy.php. Return value: 1"

Any ideas why this might be happening?

Thanks.

stolinski commented 12 years ago

Same here. It has never worked for me, getting the same error with a return value of... HtmlTidy/tidy.php. Return value: 65280

welovewordpress commented 12 years ago

If you get this error, please follow these steps:

  1. open the Sublime Text Console
  2. search for a line starting with ´HtmlTidy: calling script: ´
  3. copy and paste the command following ´HtmlTidy: calling script: ´ to the command line and press Enter.
  4. now you should see the "real" error message - whatevery went wrong while calling the script, please just copy the error message here.

I'm terribly sorry for any problems on windows, but I developed and tested it only in OS X. For supporting Windows, I rely on your feedback at the moment.

But since PhpTidy is working, we should be able to get HtmlTidy to work as well. ;-)

stolinski commented 12 years ago

Hm am I missing something here in these directions? How do I search for the line within Sublime Text console?

welovewordpress commented 12 years ago

@stolinski First, you open the sublime console via Menu "View" -> "Show Console".

Next, you call HtmlTidy and you will see some lines showing up in the console window. All output from HtmlTidy is prefixed with HtmlTidy: and on my machine, it looks like this:

HtmlTidy: invoked on file: /Users/username/Documents/Sublime Projects/test.php
HtmlTidy: buffer written to tmpfile: /tmp/htmltidy-sublime-buffer.tmp
HtmlTidy: calling script: "/usr/bin/php" "/Users/username/Library/Application Support/Sublime Text 2/Packages/HtmlTidy/tidy.php" "/tmp/htmltidy-sublime-buffer.tmp"  --wrap=100 --wrap-attributes=0 --break-before-br=0 --indent-attributes=0 --clean=0
HtmlTidy: tmpfile was processed and removed

So, it's the 3rd line we are looking for: It says that it will call the following script:

"/usr/bin/php" "/Users/username/Library/Application Support/Sublime Text 2/Packages/HtmlTidy/tidy.php" "/tmp/htmltidy-sublime-buffer.tmp"  --wrap=100 --wrap-attributes=0 --break-before-br=0 --indent-attributes=0 --clean=0

So this is what - in your case - I would copy and paste into the command shell, execute it, and post the result here.

Maybe you could add a little more info on what version of windows you are using and where your php comes from (wamp, xammp, ?) and which version if php you have installed (execute php.exe -v on the command line). That might help.

Fatbat commented 12 years ago

OK, here is what I have. Windows 7 64 bit. PHP is from WAMP, PHP 5.3.10, and this is the output from my console...

HtmlTidy: invoked on file: E:\Work\www\Templates\mastertemplate\h5bp-html5-boilerplate-359a13f\index.html
HtmlTidy: buffer written to tmpfile: C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-sublime-buffer.tmp
HtmlTidy: calling script: "php.exe" "C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/tidy.php" "C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-sublime-buffer.tmp"  --wrap-attributes=0 --break-before-br=0 --indent-spaces=2 --indent-attributes=0 --clean=0
HtmlTidy: script returned: 1
error: There was an error calling the script at C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/tidy.php. Return value: 1

Thanks for your help.

stolinski commented 12 years ago

Here is mine.

SyntaxError: unexpected EOF while parsing
HtmlTidy: invoked on file: /Users/scott/Library/Caches/Cleanup At Startup/Transmit/9B85A308-0280-42A5-BD37-869AB2217A4D/send.php
HtmlTidy: buffer written to tmpfile: /tmp/htmltidy-sublime-buffer.tmp
HtmlTidy: calling script: "/usr/bin/php" "/Users/scott/Library/Application Support/Sublime Text 2/Packages/HtmlTidy/tidy.php" "/tmp/htmltidy-sublime-buffer.tmp"  --wrap=100 --wrap-attributes=0 --break-before-br=0 --indent-attributes=0 --clean=0
HtmlTidy: script returned: 65280 
error: There was an error calling the script at /Users/scott/Library/Application Support/Sublime Text 2/Packages/HtmlTidy/tidy.php. Return value: 65280
welovewordpress commented 12 years ago

Ok, but this is only until step 2.

Both of you need to open your command line ( command shell / "dos prompt" on windows - Terminal on OS X) and try to execute the command that the plugin tries to execute.

@stolinski you should open Terminal.app, paste this line into it and press Enter:

"/usr/bin/php" "/Users/scott/Library/Application Support/Sublime Text 2/Packages/HtmlTidy/tidy.php" "/tmp/htmltidy-sublime-buffer.tmp" --wrap=100 --wrap-attributes=0 --break-before-br=0 --indent-attributes=0 --clean=0

@Fatbat you should open your windows command shell (aka "dos prompt"), paste this line and press Enter:

"php.exe" "C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/tidy.php" "C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-sublime-buffer.tmp"  --wrap-attributes=0 --break-before-br=0 --indent-spaces=2 --indent-attributes=0 --clean=0

Only the manual execution on the command line will (hopefully) output any meaningful error message.

@stolinski I wonder where this line in your console comes from:

SyntaxError: unexpected EOF while parsing

Maybe there is another problem on your installation? Maybe you should try and check out what causes this line.

stolinski commented 12 years ago

I'm sorry, ignore that line.. copy and pasting error.

Terminal output:

Fatal error: Class 'Tidy' not found in /Users/scott/Library/Application Support/Sublime Text 2/Packages/HtmlTidy/tidy.php on line 75

Fatbat commented 12 years ago

Alrighty then, here's what I got...

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Brad>"php.exe" "C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/H tmlTidy/tidy.php" "C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages/HtmlTid y/htmltidy-sublime-buffer.tmp" --wrap-attributes=0 --break-before-br=0 --indent -spaces=2 --indent-attributes=0 --clean=0 PHP Fatal error: Class 'Tidy' not found in C:\Users\Brad\AppData\Roaming\Sublim e Text 2\Packages\HtmlTidy\tidy.php on line 75 PHP Stack trace: PHP 1. {main}() C:\Users\Brad\AppData\Roaming\Sublime Text 2\Packages\HtmlTidy \tidy.php:0

Fatal error: Class 'Tidy' not found in C:\Users\Brad\AppData\Roaming\Sublime Tex t 2\Packages\HtmlTidy\tidy.php on line 75

Call Stack: 0.0007 658512 1. {main}() C:\Users\Brad\AppData\Roaming\Sublime Text 2 \Packages\HtmlTidy\tidy.php:0

C:\Users\Brad>

welovewordpress commented 12 years ago

@stolinski That's interesting. At least, it's something we can work with.

But I'm afraid that's something that would require some research on your side. Because the HtmlTidy plugin relies on the Tidy class build into PHP5, it needs to be installed on your system. I can't just bundle it with the plugin.

So, I really need to know which OS (version) you're using, which version of php (execute php -v in terminal) and if you have installed any other related things like PECL. I found this link that suggests, there might be an alternative version of Tidy interferring with the default one: http://www.karlrixon.co.uk/writing/tidy-php-fatal-error-class-tidy-not-found/

It might also be possible that you're using PHP4, which doesn't (usually) include Tidy. You would have to upgrade then...

welovewordpress commented 12 years ago

@Fatbat Ok, so you've got the same error message Class 'Tidy' not found but on Windows using WAMP.

I just googled at bit and found that maybe you have to enable Tidy in the settings of WAMP:

http://stackoverflow.com/questions/2704359/php-wamp-install-php-tidy

Let me know, if this helped. I will include it it the readme then.

stolinski commented 12 years ago

Hm, using PHP 5.3.8. Osx 10.6.8

Fatbat commented 12 years ago

Unfortunately that didn't do it. I activated the tidy extension and restarted all services but when I run HtmlTidy I get the same error. PhpTidy does work and that calls on Tidy too does it not?

welovewordpress commented 12 years ago

@Fatbat No PhpTidy uses a php script which does all the work. It requires PHP, yes. But it doesn't require any fancy PHP modules installed like this "Tidy" module.

The "Tidy" class, which is included within PHP as actually a port of an older C program called tidy. And tidy cleans up HTML only.

So, no, it's not the same. PhpTidy comes bundled with most of the "intelligence" while HtmlTidy really depends on finding a recent version of PHP with a enabled and working Tidyclass on your system.

Maybe you have more than one PHP installed. When you just use php.exeon the command line, it will take the "default". Maybe this "default" one is not the one installed (and configured) by WAMP? You should try where php.exe on the command line...

welovewordpress commented 12 years ago

@stolinski I'm using PHP 5.3.8 too - on OS X 10.7.3 which should not make any difference.

I'm stumbling here... it should really work out of the box on recent versions of OS X. Maybe the output of phpinfo() would shed any light on this?

Fatbat commented 12 years ago

I do have PHP 5.3.8 installed as well but 5.3.10 is what wamp is using and what I have set in my PATH, and it is also what I see in the command line, C:\wamp\bin\php\php5.3.10\php.exe

welovewordpress commented 12 years ago

@Fatbat call your php.exe with the parameter -m, this will output a list of installed modules:

C:\wamp\bin\php\php5.3.10\php.exe -m

Does the output have a line saying tidy?

welovewordpress commented 12 years ago

@stolinski same as above - call

php -m

and let me know if there is tidy or not.

welovewordpress commented 12 years ago

Ok, maybe you guys could paste the following lines into something like debug.php call it from the command line using your php executable of choice:

<?php
echo "PHP version    : " . phpversion() . "\n";
echo "Tidy installed : " . ( extension_loaded('tidy') ? 'Yes' : 'NO' ) . "\n";
echo "Tidy version   : " . phpversion('tidy') . "\n";

On OS X and Linux you would call it like this:

php test.php

And it should output more or less this:

PHP version    : 5.3.8
Tidy installed : Yes
Tidy version   : 2.0

If you see anything less than Tidy 2.0, then try to find a different php(.exe) on your system and call debug.php with it.

stolinski commented 12 years ago

Tidy did not show up for me when I did php -m.

welovewordpress commented 12 years ago

@stolinski Ok, there actually seems to be an issue with Tidy within PHP on OS X 10.6.

Could you do one more thing for me, please? Just execute

which tidy

in the Terminal. You might have the actual executable in /usr/bin/tidy.

I'm going to support this executable in the next version. But this requires lots of changes and won't be done today. And before that, I'd like to try if I can use this approach: http://projectbee.org/blog/archive/download-php-tidy-extension-for-mac-os-x/

stolinski commented 12 years ago

Cool, thanks for helping with everything, I'll be sure to install htmltidy on my home machine that has 10.7 and use in the meantime. I got

/usr/bin/tidy

With the which tidy

welovewordpress commented 12 years ago

@stolinski Ok, could you please try another thing ?

add the following line to debug.php:

dl('tidy.so');

and execute it as before. It will throw an error, which on my machine looks like this:

Warning: dl(): Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/tidy.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/tidy.so, 9): image not found in /Users/krok/Desktop/test.php on line 6

Do you get something similar? Then I would try the approach mentioned ob projectbee.org...

shutupandshave commented 12 years ago

I've been through this process in Windows 7, firstly I had to manually enable tidy in the PHP.INI, even though WAMP said it was enabled. I now get no error message when I run the command from the CMD prompt, however I am still getting the error in sublime text (which I have tried restarting).

welovewordpress commented 12 years ago

@shutupandshave Sublime Text will only check for updates on restart if the last update check was more than 1 hour ago. You should update the plugin manually via Package Control: Upgrade Package.

To all: I just changed to plugin to use the native command line version of tidy and only use the php class as a fallback.

On OS X, tidy seems to be included since Tiger and sits at /usr/bin/tidy. On Linux it should be there as well.

To make it as easy as possible, I included the windows version tidy.exe within the plugin. In theory, it should work out of the box now, whatever and whereever your php is. But I haven't tested it yet on windows.

Could please someone test it on windows and (even if it works) post the console output?

@stolinski It should work on your 10.6 machine now. Could you confirm that?

shutupandshave commented 12 years ago

HtmlTidy: calling tidy: "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/win/tidy.exe" --indent-spaces 4 --tab-size 4 --break-before-br 0 --wrap-attributes 0 --indent-attributes 0 --clean 0 --indent 1 --tidy-mark 0 -q -m -f "/tmp/htmltidy-error-log.tmp" "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-error-log.tmp" HtmlTidy: tidy returned error code: 1 Traceback (most recent call last): File ".\sublimeplugin.py", line 350, in run File ".\html_tidy.py", line 82, in run IOError: [Errno 2] No such file or directory: '/tmp/htmltidy-error-log.tmp'

welovewordpress commented 12 years ago

Sorry, that should be fixed now.

shutupandshave commented 12 years ago

I'm still getting that error message, after deleting and reinstalling the package.

welovewordpress commented 12 years ago

@shutupandshave Hm, exactly the same error message? That seems nealry impossible - it should at least not say /tmp/ but another path when looking for the error log.

But maybe there is no error and no warning in your file and maybe tidy doesn't write the file in that case...

so I just pushed an update where it checks the error log for existence before it tries to read it. should have included that before...

Now, you should definitely get a different error message. Or maybe none ;-)

Fatbat commented 12 years ago

It works fine here now!

stolinski commented 12 years ago

Works great after the update thank you so much for helping!

shutupandshave commented 12 years ago

"C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/win/tidy.exe" --indent-spaces 4 --tab-size 4 --break-before-br 0 --wrap-attributes 0 --indent-attributes 0 --clean 0 --indent 1 --tidy-mark 0 -q -m -f "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-error-log.tmp" "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-sublime-buffer.tmp" HtmlTidy: tidy returned error code: 1 HtmlTidy: tmpfile was processed and removed

welovewordpress commented 12 years ago

@shutupandshave does that mean it doesn't work for you?

That tidy returns an error code does not have to mean something, as it will return 0 only if there are not even warnings about the HTML.

If it still doesn't work for you, then you should call the mentioned tidy.exe manually from the command line to confirm that this binary runs on your system. But it seems to run on Fatbats Windows system.

shutupandshave commented 12 years ago

It runs, let me do a little more investigation

shutupandshave commented 12 years ago

It's running, but I'm not seeing any formatting of the HTML document, which is what I expected, in fact nothing seems to change at all?

welovewordpress commented 12 years ago

@shutupandshave I'm sorry, but I can't see what should go wrong - it's running for the others now, os OS X and Windows. And if tidy can be executed, there shouldn't be any problem reading the modified file.

What happens, if you try to tidy an empty file with just hello world in it? On my machine, it embeds this into a complete html document... but if you have a clean and idented document, maybe it doesn't do anything.

shutupandshave commented 12 years ago

On mine, nothing happens:

HtmlTidy: invoked on file: D:\Documents\Work\test1.htm HtmlTidy: buffer written to tmpfile: C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-sublime-buffer.tmp HtmlTidy: use_tabs: True HtmlTidy: tab_size: 4 HtmlTidy: calling tidy: "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/win/tidy.exe" --indent-spaces 4 --tab-size 4 --break-before-br 0 --wrap-attributes 0 --indent-attributes 0 --clean 0 --indent 1 --tidy-mark 0 -q -m -f "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-error-log.tmp" "C:\Users\James Lawrence\AppData\Roaming\Sublime Text 2\Packages/HtmlTidy/htmltidy-sublime-buffer.tmp" HtmlTidy: tidy returned error code: 1 HtmlTidy: tmpfile was processed and removed

It appears everything is working perfectly, I just dont see it doing anything - and as I said, I've run it from the command line and it appears to do work (but does nothing) there too.

welovewordpress commented 12 years ago

I'm closing this issue since the original issue is about "Error calling script?" and this error has been solved for both users who had this issue since I switched from the PHP version of tidy to the native executable.

@shutupandshave If your problem persists, please open another issue where we can discuss it further.