metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Error while using with gulpsmith #41

Closed saneef closed 9 years ago

saneef commented 9 years ago

I was using metalsmith-templates so far. Since it's deprecated, today I decided to use metalsmith-layouts. I use gulpsmith so I can use metalsmith with gulp. But, I'm getting this error when I started using metalsmith-layouts. Any ideas why it is happening?

/Users/saneef/workspace/saneef/saneef.com/node_modules/gulpsmith/node_modules/vinyl/index.js:110
      throw new Error("File.contents can only be a Buffer, a Stream, or null."
            ^
Error: File.contents can only be a Buffer, a Stream, or null.
    at File.Object.defineProperty.set (/Users/saneef/workspace/saneef/saneef.com/node_modules/gulpsmith/node_modules/vinyl/index.js:110:13)
    at new File (/Users/saneef/workspace/saneef/saneef.com/node_modules/gulpsmith/node_modules/vinyl/index.js:25:17)
    at Function.gulpsmith.to_vinyl (/Users/saneef/workspace/saneef/saneef.com/node_modules/gulpsmith/gulpsmith.js:211:18)
    at /Users/saneef/workspace/saneef/saneef.com/node_modules/gulpsmith/gulpsmith.js:124:43
    at Metalsmith.<anonymous> (/Users/saneef/workspace/saneef/saneef.com/node_modules/gulpsmith/gulpsmith.js:127:17)
    at Immediate._onImmediate (/Users/saneef/workspace/saneef/saneef.com/node_modules/metalsmith/node_modules/unyield/node_modules/co/index.js:52:14)
    at processImmediate [as _immediateCallback] (timers.js:358:17)
ismay commented 9 years ago

Difficult to tell with just the error. Metalsmith-layouts should always return file.contents unaltered or as a buffer (see here). Which is exactly the same as what metalsmith-templates did.

So I'm not sure why you're getting this error after your switch to metalsmith-layouts. Try and set up a reduced test case. That way it'll be easier to isolate the problem.

saneef commented 9 years ago

@ismay Sure. Will try with a reduced test case

ismay commented 9 years ago

Ok, I'll close this because it doesn't appear to be a metalsmith-layouts specific problem. But if the problem is due to metalsmith-layouts please let me know!

saneef commented 9 years ago

@ismay I created a tiny test project for isolating this bug. Here is the link https://github.com/saneef/metalsmith-layouts-test. It has only template rendering, and works fine with metalsmith-templates but fails with metalsmith-layouts.

ismay commented 9 years ago

I'd say that this issue is gulpsmith related. Try and debug what's going wrong with gulpsmith, because metalsmith-layouts shouldn't be returning any file.contents that aren't buffers.

From your setup it seems like you don't have any problems with your configuration at least, as far as metalsmith is concerned.

saneef commented 9 years ago

Will check. But it's quite strange since both metalsmith-in-place and metalsmith-templates works with gulpsmith.

ismay commented 9 years ago

I agree. Still, if metalsmith-layouts by itself wouldn't properly return file.contents we'd be seeing this error without gulpsmith as well. So I'd say this is an interaction with gulpsmith, on gulpsmith's side. Let me know if you find anything specific that metalsmith-layouts is doing wrong though.

ismay commented 9 years ago

By the way, you've probably noticed this yourself already, but you're missing a layout key in the front-matter in your source. That would at least explain why it isn't applying a layout. It will however still pass the file through unmodified, see here.

Let me know if you find out anything more.

saneef commented 9 years ago

Yes, you are right.

I found that hard way. Unfortunately, the contents getting from gulpsmith as well as gulp-smith is String. There is in no ignore case (when meta data layout is note present) like in metalsmith-layouts for metalsmith-templates and metalsmith-in-place. So didn't see any errors. :disappointed:

ismay commented 9 years ago

Unfortunately, the contents getting from gulpsmith as well as gulp-smith is String

I don't know if I understand exactly what you mean, but contents shouldn't be a String. See if gulpsmith changes file.contents in any way.

saneef commented 9 years ago

Yes, it's shouldn't be in String but it is.

I added console.log(typeof data.contents); after the line https://github.com/superwolff/metalsmith-layouts/blob/master/lib/index.js#L108, and run with gulpsmith. And, the result is string. Sigh.

ismay commented 9 years ago

Well at that point it should be a string. It's converted back to a buffer here. Check with gulpsmith. This shouldn't be a metalsmith-layouts issue.

pjeby commented 9 years ago

The error is at line 112: because of the early exit, files without a layout are left as strings and not converted back to buffers.

ismay commented 9 years ago

Ah that's probably it. Thanks for reporting!

ismay commented 9 years ago

@saneef This should be fixed in 1.4.1, could you confirm if this solves the error you were getting? Thanks for reporting this btw.!

saneef commented 9 years ago

Totally

Yes, it worked!

ismay commented 9 years ago

No problem

:+1: Cool, thanks again for reporting the bug and replying so quickly!