yiisoft / yii2-swiftmailer

Yii 2 swiftmailer extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
116 stars 74 forks source link

Catched swift exception still messes up page output #38

Closed mikehaertl closed 7 years ago

mikehaertl commented 7 years ago

What steps will reproduce the problem?

Render a faulty mail message that throws a Swift exception. For example attach a file that does not exist.

What's expected?

If you catch the exception, no extra output should be generated on the web page.

What do you get instead?

When rendering the mail body, PHP output buffering is used. When the exception is thrown, the buffer is obviously not cleared correctly. So the parts of the mail that rendered successful before the exception happened now appear in the web output, even when you catch the exception.

Additional info

Q A
Yii version 2.0.10
PHP version 7.0.8
Operating system Ubuntu 14.04 LTS
cebe commented 7 years ago

could you create a failing unit test for this?

mikehaertl commented 7 years ago

Sorry, will not find time for a unit test. It's not a simple test as you somehow have to capture/compare web output. No idea how to handle this in a unit test.

klimov-paul commented 7 years ago

This issue does not belong to yii2-swiftmailer it is a general problem of yii\base\View::render().

To reproduce: 1) Create web controller action:

    public function actionRender()
    {
        try {
            return $this->render('exception');
        } catch (\Exception $e) {
            return $this->render('index');
        }
    }

2) Create view file exception.php:

<h1>File Begin</h1>
<?php throw new Exception('test'); ?>
<h1>File End</h1>

The first line in rendered page will be <h1>File Begin</h1>

klimov-paul commented 7 years ago

Migrated to https://github.com/yiisoft/yii2/issues/13058