TemplateException - after git clone today #604

Closed
tonyeung opened this Issue Aug 4, 2012 · 16 comments

5 participants

@tonyeung
tonyeung commented Aug 4, 2012

( ! ) Fatal error: Uncaught exception 'lithium\template\TemplateException' with message 'Could not write compiled template C:\Users\Master\Documents\Visual Studio 2010\Projects\PSER\PSER/resources/tmp/cache/templates/template_views_pages_index.html_0_1344056913_326.php to cache.' in C:\Users\Master\Documents\Visual Studio 2010\Projects\libraries\lithium\template\view\Compiler.php on line 81
( ! ) lithium\template\TemplateException: Could not write compiled template C:\Users\Master\Documents\Visual Studio 2010\Projects\PSER\PSER/resources/tmp/cache/templates/template_views_pages_index.html_0_1344056913_326.php to cache. in C:\Users\Master\Documents\Visual Studio 2010\Projects\libraries\lithium\template\view\Compiler.php on line 81
Call Stack

Time Memory Function Location

1 0.1070 331944 {main}( ) ..\index.php:0
2 0.2013 4387040 lithium\action\Dispatcher::run( ???, ??? ) ..\index.php:41
3 0.2013 4388248 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Dispatcher.php:155
4 0.2013 4389784 lithium\util\collection\Filters::run( ???, ???, ??? ) ..\StaticObject.php:126
5 0.2014 4391752 {closure}( ???, ???, ??? ) ..\Filters.php:183
6 0.2015 4391752 lithium\util\collection\Filters->next( ???, ???, ??? ) ..\cache.php:46
7 0.2015 4391784 {closure}( ???, ???, ??? ) ..\Filters.php:202
8 0.2075 4427760 lithium\util\collection\Filters->next( ???, ???, ??? ) ..\action.php:51
9 0.2075 4427792 lithium\action{closure}( ???, ???, ??? ) ..\Filters.php:202
10 0.2198 4534776 lithium\core\StaticObject::invokeMethod( ???, ??? ) ..\Dispatcher.php:154
11 0.2198 4534808 lithium\action\Dispatcher::_call( ???, ???, ??? ) ..\StaticObject.php:75
12 0.2198 4535896 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Dispatcher.php:265
13 0.2198 4536152 lithium\action{closure}( ???, ???, ??? ) ..\StaticObject.php:119
14 0.2198 4536152 lithium\action\Controller->__invoke( ???, ???, ??? ) ..\Dispatcher.php:262
15 0.2199 4537752 lithium\core\Object->_filter( ???, ???, ???, ??? ) ..\Controller.php:198
16 0.2199 4538032 lithium\action{closure}( ???, ???, ??? ) ..\Object.php:238
17 0.2199 4538280 lithium\core\Object->invokeMethod( ???, ??? ) ..\Controller.php:184
18 0.2200 4538312 app\controllers\PagesController->view( ) ..\Object.php:165
19 0.2200 4538824 lithium\action\Controller->render( ??? ) ..\PagesController.php:32
20 0.2204 4541320 lithium\net\http\Media::render( ???, ???, ??? ) ..\Controller.php:266
21 0.2205 4550368 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Media.php:593
22 0.2206 4550616 lithium\net\http{closure}( ???, ???, ??? ) ..\StaticObject.php:119
23 0.2208 4553656 lithium\core\StaticObject::invokeMethod( ???, ??? ) ..\Media.php:590
24 0.2208 4553984 lithium\net\http\Media::_handle( ???, ???, ??? ) ..\StaticObject.php:75
25 0.2208 4555936 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Media.php:750
26 0.2209 4556184 lithium\net\http{closure}( ???, ???, ??? ) ..\StaticObject.php:119
27 0.2257 4579800 lithium\template\View->render( ???, ???, ??? ) ..\Media.php:746
28 0.2259 4583520 lithium\template\View->_step( ???, ???, ???, ??? ) ..\View.php:328
29 0.2259 4587040 lithium\core\Object->_filter( ???, ???, ???, ??? ) ..\View.php:389
30 0.2260 4587304 lithium\template{closure}( ???, ???, ??? ) ..\Object.php:238
31 0.2260 4587336 lithium\template\view\adapter\File->template( ???, ??? ) ..\View.php:386
32 0.2272 4588624 lithium\template\view\Compiler::template( ???, ??? ) ..\File.php:133

@jails
Contributor
jails commented Aug 4, 2012

This is related to #559 imo.

@mehlah
Contributor
mehlah commented Aug 4, 2012

@tonyeung your resources/tmp/cache directory should be writeable to allow Lithium write compiled templates.

chmod -R 777 resources

@jails
Contributor
jails commented Aug 4, 2012

Yeah and before, don't forget to apt-get remove windows and apt-get install linux ! ;-)

@tonyeung
tonyeung commented Aug 4, 2012

as @jails mentioned, i'm on windows, chmod doesn't apply. I've edited the security settings for my project folder to allow full control to 'everyone'. Didn't help.

I've changed the compiler fallback to true and that seems to have fixed the problem.
From what I'm reading, that means that it will not throw errors if the cache folder is not writable for some reason, and that is bad. I'd like to turn it back to false, but I'm not sure what I can do to fix the problem. A user on SO commented that it could be an issue with the slashes.

@jails
Contributor
jails commented Aug 5, 2012

I notice a weird thing in your path : "...Projects\PSER\PSER/resources...". PSER is present 2 times did you really have a "PSER" directory inside another "PSER" directory ?
Did you check your Libraries:: add() path ?

@tonyeung
tonyeung commented Aug 5, 2012

@jails good eye, but that was on purpose. That happened when I switched from developing on an apache dev server to developing with the internal apache server in visual studio (vs.php plugin).

The path used to be htdocs/PSER/(lithium framework and site).

When I switched to developing on visual studio, and made PSER the root directory, everything broke. The reason being when I developed the site originally, it was in a sub directory under the root (htdocs). All the links assumed that the site was in a sub directory.

Either way, when published, the site url is www . domain . com/PSER/(controller/action or custom route)

@daschl
Member
daschl commented Aug 5, 2012

To me, this sounds like a classical windows permission issue. For some reason, Windows 7 doesn't allow you to set write permission on certain folders. Try to move it to a different directory where it is allowed.

Btw, I don't think this is a Lithium issue.

@tonyeung
tonyeung commented Aug 5, 2012

I ran this test code and it was able to write out the test file.
My assumption is that if the test file is written, the the problem would not be on the Windows end.
However, my knowledge of the inner workings of lithium is nearly non existent.

The test code was also run in C:\Users\Master\Documents\Visual Studio 2010\Projects\

    $myFile = $_SERVER['DOCUMENT_ROOT'] . '\\ABC\\testFile.txt';
    $fh = fopen($myFile, 'w') or die('can\'t open file');
    $stringData = 'Bobby Bopper\n';
    fwrite($fh, $stringData);
    $stringData = 'Tracy Tanner\n';
    fwrite($fh, $stringData);
    fclose($fh);
@mehlah
Contributor
mehlah commented Aug 5, 2012

Your test doesn't prove that your resources/tmp/cache/templates directory is writeable.
Anyway, this exception is raised only if this directory isn't writeable.
Either this path is not found, or isn't writeable.

see: https://github.com/L-P/lithium/blob/b2b3fb1d880c041f317b05710148ab0b643a6a91/template/view/Compiler.php#L81

@tonyeung
tonyeung commented Aug 5, 2012

It seems that the problem was that the template directory under cache didn't exist.
Is this something new?

I checked my production site and the template directory doesn't exist either.
Did I just exclude that directory by mistake or is my framework that old?

@mehlah
Contributor
mehlah commented Aug 5, 2012

It's included by default whether you use li3 library extract or clone the framework repo.

@jails
Contributor
jails commented Aug 5, 2012

@tonyeung is this issue can be closed ?

@tonyeung
tonyeung commented Aug 6, 2012

I've added this code to create the directory structure into the file for anyone who doesn't want to keep the directory structure of the tmp folder in source control. The code change only affects cache writing for templates.

I'm not sure if you guys want to add this or not, so I'll just post the code here. If you think it should get added into the framework and want me to add it into the repository, I'll need some instructions on how to do that, since I only know how to do git clones to get new versions.

template/view/Compiler.php code starts at line 69

        $pathIsWritable = is_writable($cachePath);      
        if(!$pathIsWritable){
            $exMessage = ' File not writable. ';
            if(!file_exists($cachePath)) {
                $exMessage .= 'Path to file invalid. ';
                $dirCreated = mkdir($cachePath, 0777, true);

                if($dirCreated) {
                    $pathIsWritable = true;
                }
                else {
                    $exMessage .= 'Attempt to create the directory path failed.';   
                }
            }           
        }

        if ($pathIsWritable && file_put_contents($template, $compiled) !== false) {
@daschl
Member
daschl commented Aug 6, 2012

@tonyeung We already have the pre-check in the framework code. Can you verify if this correctly shows that the resource directory is not writable?

Because if this isn't working correctly, i'd rather modify the code there.

@tonyeung
tonyeung commented Aug 7, 2012

@daschl I wasn't aware there was one. I can verify the directory is writable.
I tested this by adding code to write to the directory right before the cache gets written, and also verified that the cache file gets written. If I remove the template folder then the same error will show up.

@nateabele
Member

The directory definitely exists by default: https://github.com/UnionOfRAD/framework/tree/master/app/resources/tmp/cache/templates

Since this hasn't come up for anyone else (even on Windows), I'm going to assume it's an isolated incident. We'll probably include these kinds of checks in a diagnostic tool if some kind, but I'd rather not do any check-and-create in the core.

@nateabele nateabele closed this Sep 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment