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

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

Closed
silvenon opened this issue Jun 23, 2020 · 8 comments · Fixed by posthtml/gulp-posthtml#16
Closed

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

silvenon opened this issue Jun 23, 2020 · 8 comments · Fixed by posthtml/gulp-posthtml#16

Comments

@silvenon
Copy link

silvenon commented Jun 23, 2020

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
Copy link
Member

Scrum commented Jun 25, 2020

@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
Copy link
Author

silvenon commented Jun 25, 2020

@Scrum
Copy link
Member

Scrum commented Jun 25, 2020

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
Copy link
Author

silvenon commented Jun 25, 2020

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.

silvenon added a commit to silvenon/gulp-posthtml that referenced this issue Jun 25, 2020
- rename Error to PluginError to not shadow actual Error
- consistenly use PluginError
- handle posthtml-expressions errors by not passing the error object
directly

posthtml/posthtml-expressions#89 (comment)
silvenon added a commit to silvenon/gulp-posthtml that referenced this issue Jun 25, 2020
- rename Error to PluginError to not shadow actual Error
- consistenly use PluginError
- handle posthtml-expressions errors by not passing the error object
directly
- show error stack, which is very useful for this plugin

posthtml/posthtml-expressions#89 (comment)
silvenon added a commit to silvenon/gulp-posthtml that referenced this issue Jun 25, 2020
- rename Error to PluginError to not shadow actual Error
- consistenly use PluginError
- handle posthtml-expressions errors by not passing the error object
directly
- show stack which is very useful for plugins like this

posthtml/posthtml-expressions#89 (comment)
@Scrum
Copy link
Member

Scrum commented Jun 26, 2020

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
Copy link
Author

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
Copy link
Member

Scrum commented Jul 23, 2020

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
Copy link
Author

😄

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 a pull request may close this issue.

2 participants