Visitar URL original
Repository.writeFile fails if no options object is passed · Issue #577 · github-tools/github · GitHub
The Wayback Machine - https://web.archive.org/web/20200920060440/https://github.com/github-tools/github/issues/577
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

Repository.writeFile fails if no options object is passed #577

Open
lantchou opened this issue Aug 9, 2019 · 3 comments
Open

Repository.writeFile fails if no options object is passed #577

lantchou opened this issue Aug 9, 2019 · 3 comments

Comments

@lantchou
Copy link

@lantchou lantchou commented Aug 9, 2019 •

In the documentation about Repository.writeFile, the options parameter is specified as optional. Despite this, the function fails if no options object is passed and throws this error:

TypeError: Cannot read property 'encode' of undefined
    at Repository.writeFile (/Users/lucasantchougov/Documents/Work/oauth-rule-manager/node_modules/github-api/dist/components/Repository.js:941:37)
    at GitHubRuleManager.commitWorkspace (/Users/lucasantchougov/Documents/Work/oauth-rule-manager/lib/rule_managers/github-rule-manager.js:143:18)
    at /Users/lucasantchougov/Documents/Work/matey/matey-server/app.js:74:25
    at Layer.handle [as handle_request] (/Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/layer.js:95:5)
    at /Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/index.js:281:22
    at param (/Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/index.js:354:14)
    at param (/Users/lucasantchougov/Documents/Work/matey/matey-server/node_modules/express/lib/router/index.js:365:14)

The error seems to get thrown when options.encode is read in Repository.writeFile. It only works for me when passing an empty object. This should be better documented or a default empty object should be instantiated in the method.

@CodyGramlich
Copy link
Contributor

@CodyGramlich CodyGramlich commented Sep 21, 2019

It seems to work without having the options parameter when the callback function is used, but ideally you should be able to call writeFile without either the options parameter or the callback function. I will look into this.

@CodyGramlich
Copy link
Contributor

@CodyGramlich CodyGramlich commented Sep 21, 2019

I just realized this is solved in PR #588.

@j-rewerts
Copy link
Member

@j-rewerts j-rewerts commented Oct 8, 2019

After looking at this a little more closely, it looks like our old approach was to require a callback. If a function was provided as the options param, we would assume that the user was passing in the callback function. When we added promises, people stopped using callbacks, so we can no longer assume that this is a required parameter (even though the docs say it is).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
@j-rewerts @CodyGramlich @lantchou and others
You can’t perform that action at this time.