posthtml / posthtml-expressions

Use variables, JS-like expressions, and even markup-powered logic in your HTML.
Other
123 stars 20 forks source link

Errors thrown by this plugin are not instances of Error #89

Closed silvenon closed 4 years ago

silvenon commented 4 years ago

Problem

I'm using posthtml-expressions with gulp-posthtml, but every time I make a mistake (e.g. try to access a property of undefined) gulp-posthtml throws with "Missing error message" instead of displaying a descriptive error message like it does when running posthtml directly. (This is not a problem with gulp-posthtml, read further.)

Details

Eventually I found out that the "Missing error message" error was coming from plugin-error, so gulp-posthtml threw when attempting to emit an error πŸ˜„ I confirmed that this failure only happens for errors thrown specifically by posthtml-expressions. This is because plugin-error checks whether the argument is an instance of Error.

Is this problem solvable or should I submit a PR to gulp-posthtml which fixes this in another way?

Error Logs

  Error: Missing error message
new PluginError (node_modules/plugin-error/index.js:64:11)
index.js:85:14

Issue [ Code ]

Catch any error thrown by a vm.runInContext call and you can verify that it's indeed not an instance of Error.

Environment

Please provide information about your environment.

OS Node npm PostHTML
macOS 10.15.5 14.4.0 6.14.5 N/A
Scrum commented 4 years ago

@silvenon Could you give a link to the repository where this can be reproduced?

Now I can’t give a definite answer, I need to see what happens.

silvenon commented 4 years ago

Repro: https://github.com/silvenon/repro/tree/posthtml-expressions-error

Scrum commented 4 years ago

Repro: https://github.com/silvenon/repro/tree/posthtml-expressions-error

+cb(new Error(PLUGIN_NAME, err.message))

I think this solution is more correct, it may be worth updating this package because It has not been updated for a long time.

Why do you use gulp ?

silvenon commented 4 years ago

Technically it's a workaround, so first I wanted to see if there was a way to solve the issue at the root ("the right way"), but for my purposes it's fine either way, so I'll submit a PR to gulp-posthtml.

I use gulp to build static sites, gulp v4 kinda changed the game for me. I have a bunch of HTML pages which I process with posthtml (sometimes first markdown, then posthtml) and output. Static site generators feel either too restrictive or too cumbersome to me. What tools do you use?

Closing this because I'l solve this in gulp-posthtml.

Scrum commented 4 years ago

I use gulp to build static sites, gulp v4 kinda changed the game for me. I have a bunch of HTML pages which I process with posthtml (sometimes first markdown, then posthtml) and output. Static site generators feel either too restrictive or too cumbersome to me. What tools do you use?

Exclusively for static pages I would use posthtml-cli or parceljs

silvenon commented 4 years ago

Oops, I didn't see your comment. My build step is more complex, so posthtml-cli wouldn't be enough, and a bundler like Parcel wouldn't work either, I think, because bundlers assume an entry point (or multiple of them), which fits the model of applications, but not static sites AFAIK. I haven't seen a static site built with a bundler, though, (without a framework like Gatsby) but I'm happy to be proven wrong. πŸ˜ƒ

I like gulp, though, as retro as it may seem. πŸ˜‰

Scrum commented 4 years ago

Oops, I didn't see your comment. My build step is more complex, so posthtml-cli wouldn't be enough, and a bundler like Parcel wouldn't work either, I think, because bundlers assume an entry point (or multiple of them), which fits the model of applications, but not static sites AFAIK. I haven't seen a static site built with a bundler, though, (without a framework like Gatsby) but I'm happy to be proven wrong. πŸ˜ƒ

I like gulp, though, as retro as it may seem. πŸ˜‰

There is a saying in Russia "an old friend is better than two new ones"

silvenon commented 4 years ago

πŸ˜„