Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. fixes #22 #24

Closed
wants to merge 3 commits into from

Conversation

brokolja
Copy link

Hi,

I fixed #22 by using the async version of renderString to catch/emit the error in the callback before its thrown. With this solution the gulp task will not stop on error - it will just show a message.

Greetings ,
Kolja Kutschera

@brokolja brokolja closed this Sep 19, 2017
@brokolja brokolja reopened this Sep 19, 2017
@kevva
Copy link

kevva commented Sep 19, 2017

The fix here isn't using the async version, but rather that you're using an empty string when resdoesn't exist (which will result in an empty file). I think we should find out why env.renderString(file.contents.toString(), context) returns undefined sometimes instead.

@kevva kevva closed this Sep 19, 2017
@brokolja
Copy link
Author

In: https://github.com/mozilla/nunjucks/blob/master/src/environment.js at line: 501 you can see that nunjucks throws rendering errors if no callback is used with env.renderString. So we must use env.renderString with callback to catch errors within the callback if we can not change nunjucks sourcecode. Its not possible to catch an error which is thrown within another scope. But your right it seems that using the async nunjucks render function is not a good thing here because were dealing with streams. But even if it is not the best solution - my fix fixed the problem in my gulp-task.

@kevva
Copy link

kevva commented Sep 19, 2017

If it throws we'll catch it since we're using it inside a try/catch block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
2 participants