Skip to content
This repository has been archived by the owner on Mar 12, 2018. It is now read-only.
This repository has been archived by the owner on Mar 12, 2018. It is now read-only.

"TypeError: Cannot set property message of  which has only a getter" #35

Open
chharvey opened this issue Mar 11, 2018 · 1 comment
Open

Comments

@chharvey
Copy link

err.message = (filename || 'Pug') + ':' + lineno

It appears as if pug_rethrow is attempting to set the message property of something, where message is only a getter.

Setting err.message = .. throws a TypeError, which reads:

TypeError: Cannot set property message of  which has only a getter

I’m not sure why, because the message property of any Error object should be settable. It might be the case that err is not actually an Error object.

Specs:

  • node.js v8.9.1
  • npm@5.7.1
  • gulp-pug@3.3.0
  • pug@2.0.0-rc.4
  • pug-runtime@2.0.3
Trace:
events.js:183
      throw er; // Unhandled 'error' event
      ^
TypeError: Cannot set property message of  which has only a getter
    at Object.pug_rethrow [as rethrow] (/Users/Chris/Repositories/_CLONED/neo/node_modules/pug-runtime/index.js:251:15)
    at template (eval at wrap (/Users/Chris/Repositories/_CLONED/neo/node_modules/pug-runtime/wrap.js:6:10), :837:665)
    at DestroyableTransform.compilePug [as _transform] (/Users/Chris/Repositories/_CLONED/neo/node_modules/gulp-pug/index.js:36:49)
    at DestroyableTransform.Transform._read (/Users/Chris/Repositories/_CLONED/neo/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/Users/Chris/Repositories/_CLONED/neo/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/Users/Chris/Repositories/_CLONED/neo/node_modules/readable-stream/lib/_stream_writable.js:418:64)
    at writeOrBuffer (/Users/Chris/Repositories/_CLONED/neo/node_modules/readable-stream/lib/_stream_writable.js:407:5)
    at DestroyableTransform.Writable.write (/Users/Chris/Repositories/_CLONED/neo/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at write (/Users/Chris/Repositories/_CLONED/neo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Users/Chris/Repositories/_CLONED/neo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/Users/Chris/Repositories/_CLONED/neo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at emitNone (events.js:106:13)
    at DestroyableTransform.emit (events.js:208:7)
    at emitReadable_ (/Users/Chris/Repositories/_CLONED/neo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:448:10)
    at emitReadable (/Users/Chris/Repositories/_CLONED/neo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:444:5)
    at readableAddChunk (/Users/Chris/Repositories/_CLONED/neo/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:187:9)
@ForbesLindesay
Copy link
Member

This is very odd. We actually check that it's instanceof Error before we do any of this. I would be happy to accept a pull request to wrap https://github.com/pugjs/pug/blob/master/packages/pug-runtime/index.js#L249-L251 in a try/catch block, so that we throw the original error if we were unable to update the message.

Please also note that this package has moved to the monorepo, so you'll need to put your pull request there: https://github.com/pugjs/pug/tree/master/packages/pug-runtime

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

No branches or pull requests

2 participants