question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tcpserver.js does not propagate mjml compile errors for mjml >= 3

See original GitHub issue

mjml >= 3 returns its results in a {errors: [], html: ""} object. https://github.com/liminspace/django-mjml/commit/086ffdc22ac7b4ef78802061efaacf6ffc36928b added support for mjml >= 3 by using the result.html for the output; however, the errors key in the mjml compilation result is never checked.

If mjml has a compile error, this behavior can result in blank emails going out, which is problematic. It would be much better to loudly throw an error if mjml fails to compile. Throwing errors would help to prevent that kind of reputation-harming email noise.

This alternative handleConnection function throws a RuntimeError if mjml encounters an mjml compile error:

function handleConnection(conn) {
    conn.setEncoding('utf8');
    conn.on('data', function(d) {
        var result, html;
        try {
            result = mjml.mjml2html(d.toString());
            if (result.errors.length) {
              html = JSON.stringify(result.errors, null, 2);
              conn.write('1');
            } else {
              html = result.html;
              conn.write('0');
            }
        } catch (err) {
            html = err.message;
            conn.write('1');
        }
        conn.write(('000000000' + Buffer.byteLength(html).toString()).slice(-9));
        conn.write(html);
    });
    conn.once('close', function() {});
    conn.on('error', function(err) {});
}

If you wanted to preserve backwards compatibility to older versions of mjml as the current tcpserver.js has, this would need to be modified.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yourcelfcommented, Feb 20, 2018

mjml doesn’t distinguish between error level (“errors” vs “warnings”), but with default options it is possible to have both errors and html output in the compiled result.

mjml2html does accept an options argument which could include {validationLevel: "strict"}, which causes it to throw an exception on the presence of any error - so that’s another approach that could be taken to ensure that errors are thrown, rather than inspecting the errors array.

For my use case, I’d much prefer get an exception and not send an email if there’s any possibility the email rendering was incomplete, even if it did render with warnings. In my setup now I’m running with my own version of tcpserver.js to get that behavior, so it isn’t a burden to me if you think it better for django-mjml to have a more lax setup.

0reactions
liminspacecommented, Apr 27, 2018

@yourcelf, this issue is done in next release 0.5.0. Now you can check it in develop branch. Just set up mjml option level/validationLevel with strict value, see readme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MJML compile error (via MJML TCP server): no working server ...
Hi Igor I am running the backend in docker too, which is 127.0.0.1:8000 or say 0.0.0.0:8000. Do I need extra settings inside docker-compose.yml?...
Read more >
mjml-guides – Documentation for MJML - The Responsive ...
MJML Guides. MJML is a markup language designed to reduce the pain of coding a responsive email. Its semantic syntax makes it easy...
Read more >
mjml - npm
Start using mjml in your project by running `npm i mjml`. There are 417 other projects in the npm registry using mjml.
Read more >
node.js - mjml command not found - Stack Overflow
If anyone out there uses MJML please can you help with this? I'm running it on a Mac under Mojave 10.14.2. If I...
Read more >
Top 5 mjml-validator Code Examples - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found