kriswallsmith/assetic — Issue #172: Bug: Compass Error output doesn't appear in CSS file.
Author: Kasheen
Created: 2012-01-12 22:00:00+00:00
State: open

Hello Kris,

I spoke to you recently on Stack Overflow about an issue I was having: http://stackoverflow.com/questions/8771747/asseticbundle-compassfilter-any-way-to-throw-an-exception-when-a-template-can

You kindly allowed me to post an issue on github so I did a bit more digging before doing so to try and narrow my issue down - and I have also come up with a fix (maybe?).

**The Problem:**
After you told me that Assetic could not generate the Symfony2 exception page when it failed to generate an asset you mentioned that Assetic should dump the exception to the generated CSS file - this is true but my issue then became that the stacktrace in the CSS file did not contain the Compass process's output.

To demonstrate I purposefully made a faulty ```_forms.scss``` file whereby I missed a ```$``` symbol on the variable ```span``` in the ```mixin``` named ```form-element```:

```
$form-column-width: $grid-column-width;

@mixin form-column($span) {
width: $form-column-width * $span;
}

@mixin form-element($span) {
width: ($form-column-width * span) - 20;
}
```

Compiling this file on the command line yielded the following (the error message being the "process output" that I was wanting to appear in the generated CSS file:

```
compass compile .
directory ./stylesheets/
error sass/single.scss (Line 8: Undefined operation: "40px times span".)
```

However the generated CSS file contained a stacktrace without this error message:

```
[exception] 500 | Internal Server Error | RuntimeException
[message] [31m[0m
[1] RuntimeException: [31m[0m
at n/a
in /var/www/egd/vendor/assetic/src/Assetic/Filter/CompassFilter.php line 278

at Assetic\Filter\CompassFilter->filterLoad(object(Assetic\Asset\FileAsset))
in /var/www/egd/vendor/assetic/src/Assetic/Filter/FilterCollection.php line 62

at Assetic\Filter\FilterCollection->filterLoad(object(Assetic\Asset\FileAsset))
in /var/www/egd/vendor/assetic/src/Assetic/Asset/BaseAsset.php line 83

at Assetic\Asset\BaseAsset->doLoad('@import '../../../../../../../app/Resources/assets/sass/public-base';

@import 'blog-post';
@import '../../../../CommentBundle/Resources/assets/sass/comments';

.blog-post {
@include blog-post;

border-bottom: 1px solid $grey-border;
}', null)
in /var/www/egd/vendor/assetic/src/Assetic/Asset/FileAsset.php line 57

at Assetic\Asset\FileAsset->load()
in /var/www/egd/vendor/assetic/src/Assetic/Asset/BaseAsset.php line 92

at Assetic\Asset\BaseAsset->dump(null)
in /var/www/egd/vendor/assetic/src/Assetic/Asset/AssetCache.php line 67

at Assetic\Asset\AssetCache->dump()
in /var/www/egd/vendor/bundles/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php line 80

at Symfony\Bundle\AsseticBundle\Controller\AsseticController->render('89b08b2', '0')
in line

at call_user_func_array(array(object(Symfony\Bundle\AsseticBundle\Controller\AsseticController), 'render'), array('89b08b2', '0'))
in /var/www/egd/app/cache/dev/classes.php line 3793

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Symfony\Component\HttpFoundation\Request), '1')
in /var/www/egd/app/cache/dev/classes.php line 3763

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Symfony\Component\HttpFoundation\Request), '1', true)
in /var/www/egd/app/cache/dev/classes.php line 4739

at Symfony\Bundle\FrameworkBundle\HttpKernel->handle(object(Symfony\Component\HttpFoundation\Request), '1', true)
in /var/www/egd/app/bootstrap.php.cache line 547

at Symfony\Component\HttpKernel\Kernel->handle(object(Symfony\Component\HttpFoundation\Request))
in /var/www/egd/web/app_dev.php line 21
```

And the relevant message also did not appear using the assetic:dump command (note that the error output here errors out on ```login.css``` because the faulty ```_forms.scss``` is a "partial" which is included in ```login.scss```):

```
php app/console assetic:dump

Dumping all dev assets.
Debug mode is on.

[file+] /var/www/egd/app/../web/bundles/egdsecurity/css/login.css

[RuntimeException]

assetic:dump [--watch] [--force] [--period="..."] [write_to]
```

**The Solution:**
After looking at the stacktrace I navigated to ```CompassFilter.php``` line ```278``` to find the following line:

```throw new \RuntimeException($proc->getErrorOutput() ?: $proc->getOutput());```

Which I found that if I modified to become:

```throw new \RuntimeException($proc->getOutput());```

Gave me almost the correct output in the generated CSS file:

```
[exception] 500 | Internal Server Error | RuntimeException
[message] [31m[0m[31m error[0m assetic_compassVCz3tJ.scss (Line 16: Undefined operation: "40px times span".)
[32m create[0m assetic_compassVCz3tJ.css

[1] RuntimeException: [31m[0m[31m error[0m assetic_compassVCz3tJ.scss (Line 16: Undefined operation: "40px times span".)
[32m create[0m assetic_compassVCz3tJ.css

// Rest of the Stacktrace was removed.
```

**Please note** that this second CSS dump was made with a different version of ```_forms.scss``` since my codebase moved forward but I put the same error into it. The only issue with the error dump is that compass reports the Assetic copied filename but that isn't really an issue for me - some error output is better than none.

I don't know if other users have the same issue as me so perhaps other people would like to pitch in - my Sass & Compass path is different from default as I noted in my Stack Overflow post:

```
assetic:
debug: %kernel.debug%
use_controller: false
sass: /var/lib/gems/1.8/bin/sass
filters:
compass:
bin: /var/lib/gems/1.8/bin/compass
apply_to: "\.scss$"
scss: ~
```

Lastly I apologise that it's such a long post, I hope it helps though. Also, thank you for making such a great tool, it certainly comes in very handy and definitely helps streamline development.

Kind Regards,
Kasheen