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

Example Error #13

Closed
angrykoala opened this issue May 31, 2016 · 8 comments
Closed

Example Error #13

angrykoala opened this issue May 31, 2016 · 8 comments

Comments

@angrykoala
Copy link

Running your example:

const wallpaper = require('wallpaper');

wallpaper.set('unicorn.jpg').then(() => {
    console.log('done');
});

wallpaper.get().then(imagePath => {
    console.log(imagePath);
    //=> '/Users/sindresorhus/unicorn.jpg'
});

On Linux Ubuntu throws an error on /lib/linux.js:

return cp.execFile(app.cmd, app.get).then(stdout => 

TypeError: Cannot read property 'cmd' of undefined

Seems to be due to using async functions (get and set) at the same time (same problem with different error if using get before set

The problem solves simply using the second command inside the callback:

const wallpaper = require('wallpaper');

wallpaper.set('unicorn.jpg').then(() => {
    console.log('done');
    wallpaper.get().then(imagePath => {
        console.log(imagePath);
        //=> '/Users/sindresorhus/unicorn.jpg'
    });
});

I'm not sure if the problem is just in linux, and if its an error in the example code or in the linux library.

@kevva
Copy link

kevva commented Jun 1, 2016

The example is just meant to show how you use the methods individually and what they return. It assumes that people know about async.

@kevva kevva closed this as completed Jun 1, 2016
@angrykoala
Copy link
Author

Wouldn't be better to use 2 different examples? just for better clarity.

@kevva
Copy link

kevva commented Jun 1, 2016

Both @sindresorhus, me and tons of authors are doing examples like this in many (small) modules. It's somewhat expected that users have some knowledge about how async works :). I.e, doing two async operations at the same time that depends on each other will mostly break.

@SamVerschueren
Copy link
Contributor

Agree with @kevva , no need to change it.

@kevva
Copy link

kevva commented Jun 1, 2016

Also, what if you expose more than two methods? To separate all those into their own examples would only clutter the documentation.

@angrykoala
Copy link
Author

If making more examples is a problem, simply by splitting the example code would show to a new user it is not meant to work with copy-paste:

wallpaper.set('unicorn.jpg').then(() => {
    console.log('done');
});
wallpaper.get().then(imagePath => {
    console.log(imagePath);
    //=> '/Users/sindresorhus/unicorn.jpg'
});

It is not a big deal, but it may make the example a little bit more clear to people who just want a first "Hello World" to try

@kevva
Copy link

kevva commented Jun 1, 2016

That's what I meant by cluttering the docs.

@angrykoala
Copy link
Author

well... it's one white line, but ok.It was just an idea

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

No branches or pull requests

3 participants