Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

[bug] imgur.saveClient not working as per docs #162

Closed
swarajpure opened this issue Apr 5, 2021 · 6 comments · Fixed by #173
Closed

[bug] imgur.saveClient not working as per docs #162

swarajpure opened this issue Apr 5, 2021 · 6 comments · Fixed by #173

Comments

@swarajpure
Copy link
Contributor

swarajpure commented Apr 5, 2021

As per the documentation:

// Setting
imgur.setClientId('aCs53GSs4tga0ikp');

// Getting
imgur.getClientId();

// Saving to disk. Returns a promise.
// NOTE: path is optional. Defaults to ~/.imgur
imgur
  .saveClientId(path)
  .then(() => {
    console.log('Saved.');
  })
  .catch((err) => {
    console.log(err.message);
  });

If we continue just like this, we get the error:

Error: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

Reason:

  • imgur.saveClientId function expects two arguments: clientId and path and we're passing only one that too wrong one. Why wrong? clientId is supposed to be the first argument and then path

What's the fix?

Short:

  • Edit the function call: saveClientId('aCs53GSs4tga0ikp', null)

Long:

  • Edit the function arguments of imgur.saveClientId to be an object and pass path as null
    Something like:
imgur.saveClientId = async ({ clientId, path = null }) => {
......
  • Then edit the function call to be saveClientId({ clientId: 'aCs53GSs4tga0ikp' })

I was struggling for some time with this issue and then finally after looking the library functions could I find the problem. Would be better if we can fix this. I know people can use the v2 but there will be people who would be using v1 as it's stable.

Thank you! 😄

@swarajpure
Copy link
Contributor Author

Once I get your approval @kaimallea I can work on this issue and send a PR :)
Also, please let me know which way should we follow, the short/long fix?

@swarajpure swarajpure changed the title Error: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined [bug]: imgur.saveClient not working as per docs Apr 6, 2021
@swarajpure swarajpure changed the title [bug]: imgur.saveClient not working as per docs [bug] imgur.saveClient not working as per docs Apr 6, 2021
@kaimallea
Copy link
Owner

kaimallea commented Apr 7, 2021

@swarajpure hey, thanks for the thorough issue! All PRs are welcome, would love for you to send in a PR fixing this. saveClientId would definitely work better if it saved a client id that was previously set with setClientId()

Out of curiousity, would it be easier for you if you passed in the client id from an environment variable, rather than saving it to disk? e.g., imgur.setClientId(process.env.IMGUR_CLIENTID);`. Also feel free to ignore my suggestion and send a PR. :)

@swarajpure
Copy link
Contributor Author

@swarajpure hey, thanks for the thorough issue! All PRs are welcome, would love for you to send in a PR fixing this. saveClientId would definitely work better if it saved a client id that was previously set with setClientId()

Thanks! Please let me know whether I should implement the long fix or the short fix. Modifying the library function might cause tests to break (if any). Just wanted to confirm once before I send in a PR 😉

Out of curiousity, would it be easier for you if you passed in the client id from an environment variable, rather than saving it to disk? e.g., imgur.setClientId(process.env.IMGUR_CLIENTID);`. Also feel free to ignore my suggestion and send a PR. :)

Yes, when I was trying it, I was loading the clientId from the environment variables only 🙂
I just copied the clientId from the README.md, just to maintain the way function calls are there in the README.md

@swarajpure
Copy link
Contributor Author

Oh, I see there is no test for saveClientId function.

I guess then modifying the library function saveClientId to take an object as parameters would be better (check the long fix in description). Let me know what you think 😄

@kaimallea
Copy link
Owner

@swarajpure since v1.x is in maintenance/support mode, I'd prefer to limit the change to a fix/patch rather than a new feature or breaking change that would require a minor or major version bump

@kaimallea kaimallea added the v1.x label Apr 11, 2021
swarajpure added a commit to swarajpure/node-imgur that referenced this issue Apr 18, 2021
saveClient function expects two arguments and according to the documentation, we were passing only
one which resulted in errors.

fix kaimallea#162
@kaimallea
Copy link
Owner

🎉 This issue has been resolved in version 1.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants