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

Create new opts object #42

Closed
wants to merge 1 commit into from
Closed

Create new opts object #42

wants to merge 1 commit into from

Conversation

nordsimon
Copy link

Hello

2 days ago i started to use this lib for consul and very quickly i ran into a weird error where papi was yelling at the baseUrl. After some digging i found out that your library is actually mutating the options object that one pass in. So when using the same options object twice in your codebase you get weird errors

example:

File 1

var config = require('./config')

var consul = require('consul')(config.consul);

File 2

var config = require('./config')

var consul = require('consul')(config.consul);

Here file 2 breaks on initialization since the the first constructor have mutated my config.consul object. This is easy to fix by just creating new object but it took me a while to figure out why papi was breaking. I also think it's good practice to handle options params as "immutable" to avoid side effects like this.

I added test to make sure the object is not referenced and updated the opts to use _.extend from user options params.

Not a major thing but this would have saved me some trouble so I hope you think it's a good idea

@silas silas closed this in db420b2 Sep 25, 2016
@silas
Copy link
Owner

silas commented Sep 25, 2016

Thanks for the PR and test!

I don't currently include lodash in the non-test dependencies, so I reworked it to use another function.

The fix has been pushed to npm in 0.26.0.

@nordsimon
Copy link
Author

Thanks!

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 this pull request may close these issues.

2 participants