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

Seneca: Cannot assign to read only property 'enabled' of object '#<Object>' #703

Closed
ikobiashvili opened this issue May 18, 2018 · 3 comments
Assignees
Labels

Comments

@ikobiashvili
Copy link

When I pass object to use() function as module options I get following error. But this happens only if the object is loaded by config. If I clone the configuration object or hardcode it, then it works fine.

Here are details:
node.js: 6.11.4, 8.9.3, 8.11.2
Seneca: 3.5.0

My conf json:

{
  "analytics":{
    "enabled": true,
    "type":"elasticsearch",
    "url":"abc"
  }
}

This was working fine previously but now produces the error:

var cfg_analytics = config.get('analytics');
seneca.use('../services/gza/event-logger.service',  cfg_analytics);

This works fine:

seneca.use('../services/gza/event-logger.service',  {url:'abc', enabled:true});

This is the error message:

=== SENECA FATAL ERROR ===
MESSAGE:  ::: seneca: Cannot assign to read only property 'enabled' of object '#<Object>'
CODE:     ::: plugin_undefined
INSTANCE  :::  Seneca/7767rwgjflva/1526638227646/23360/3.5.0/-
DETAILS   ::: {}
STACK     :::  TypeError: Cannot assign to read only property 'enabled' of object '#<Object>'
               at build_plugindesc (D:\work\projects\gveli-server\node_modules\use-plugin\use.js:150:31)
               at Object.use (D:\work\projects\gveli-server\node_modules\use-plugin\use.js:68:22)
               at Seneca.api_use [as use] (D:\work\projects\gveli-server\node_modules\seneca\seneca.js:838:29)
               at Object.<anonymous> (D:\work\projects\gveli-server\test\services\gveli-hub\users.service.test.js:14:8)
               at Module._compile (module.js:570:32)
               at Object.Module._extensions..js (module.js:579:10)
               at Module.load (module.js:487:32)
               at tryModuleLoad (module.js:446:12)
               at Function.Module._load (module.js:438:3)
               at Module.require (module.js:497:17)
WHEN      :::  2018-05-18T10:10:27.674Z
LOG       :::  {kind:null,plugin:seneca,tag:3.5.0,id:7767rwgjflva/1526638227646/23360/3.5.0/-,code:plugin_undefined,notice:sen

event-logger.service.js is normal Seneca plugin. It does not affect the error.

module.exports = function ( options ) {
  const seneca = this;
  const analytics_enabled = options.enabled === true;
  const analytics_url = options.url;
  if (analytics_enabled){
    seneca.log.info(`Using analytics at ${analytics_url}`);
  }

  seneca.add({role:'logger', event:'sync'}, (msg, reply) => {
.....

The is the line from use.js of use-plugin where the error happens:

  // Options as an argument to the _use_ function override options
  // in the plugin description object.
  plugindesc.options = Object.assign(plugindesc.options || {}, options || {})

This merging is not directly Seneca code, but to me it looks like Seneca is breaking promise to accept options for plugins. And it was working previously fine.

@rjrodger
Copy link
Collaborator

config must be freezing or sealing the options object - a bug for use-plugin

@rjrodger
Copy link
Collaborator

rjrodger/use-plugin#7

@rjrodger
Copy link
Collaborator

rjrodger commented Aug 7, 2018

This will be fixed in next release, fixed in rjrodger/use-plugin#7

@rjrodger rjrodger closed this as completed Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants