Skip to content

Stack traces are unusable for array-to-string conversions when using the yield-based system #4765

@stof

Description

@stof

I got a case where a template was doing {{ value }} and received an empty array as value (due to a bug in my code). The stack trace for that was totally useless:

Image

In the old buffer-based architecture, converting the array to a string would happen in the compiled template at the location of this {{ value }}, allowing to debug this.
The new architecture documents that Template::doDisplay should return an iterable<scalar|\Stringable|null>, but the compiled code does not actually ensure this is respected. PrintNode does not ensure that the expression result satisfies that type before yielding it.

This has 2 impact:

  • when using TemplateWrapper::render or TemplateWrapper::display (or the equivalent block-related methods), you will get warning with a useless stack trace (see my example)
  • when using TemplateWrapper::stream (or TemplateWrapper::streamBlock), the returned iterable will not satisfy the contract (and whether you get an error or warning will depend on how the iterable is consumed, but it won't have a stack trace reaching to the root cause in the PrintNode).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions