The 'data' parameter expects bytes. Bytes cannot include wide characters,
they must either be binary data or already encoded text. If you want to
pass unencoded characters, use the 'text' parameter. See
https://metacpan.org/pod/Mojolicious::Guides::Rendering#Rendering-text

-Dan

On Mon, Jan 28, 2019 at 4:45 AM Boyd Duffee <b.duf...@keele.ac.uk> wrote:

> Tracked down a bug in my code and found the reason for it wasn't
> explicitly covered in the docs.  I don't know if this is obvious or
> expected behaviour, so I'm posting for comment and for the next unfortunate
> soul STFW for this answer.
>
> I created a Data::ICal object as $calendar and added a bunch of events
> which I sent to the browser using
>
> $self->render( data => $calendar->as_string(),
>     format => 'ics', status => 200 );
>
> It worked fine until I started including a unicode character in the events
> (  \x{1f4f9} ) and then I started getting this error on STDERR
>
> Mojo::Reactor::Poll: I/O watcher failed: Wide character in subroutine
> entry at /usr/local/share/perl5/Mojo/IOLoop/Stream.pm line 86.
>
> and it refused to send the response.  The failure was hidden by some
> caching code and my lack of understanding of the render lifecycle.  Of
> course, the solution was to properly encode the datastream
>
> use Encode qw/encode_utf8/;
> ...
> $self->render( data => encode_utf8( $calendar->as_string() ),
>     format => 'ics', status => 200 );
>
> I guess I was expecting render to simply push out whatever garbage that I
> was passing off as data or maybe to emit a a more informative warning on
> development.log to realize the true impact it had on my app rather than
> puzzling over a HTTP 502 error.
>
> thoughts?
> --
> Boyd Duffee
>   They're good dogs, Brent.  Oh, h*ck. - We Rate Dogs
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to