A function wrapped with wrapAsync never returns

I’m trying to wrap a function from a node package with wrapAsync.

filepicker = new Filepicker('API Key') 
filepickerStatSync = Meteor.wrapAsync(filepicker.stat, filepicker)
result = filepickerStatSyncr(url);
console.log('after')

The stat function is below.

Everything seem to work fine… the request call responds with the correct result, the final callback is called, the whole thing executes synchronously / yields correctly as far as I can tell… but the sync call never returns and console.log(‘after’) is never hit.

Filepicker.prototype.stat = function(url, options, callback) {
    callback = callback || function(){};
    if(!options) {
        options = {};
    }
    if(!url) {
        callback(new Error('Error: no url given'));
        return; 
    }
    request({
        method: 'GET',
        url: url+'/metadata?',
        form: {
            size: options.size || true,
            mimetype: options.mimetype || true,
            filename: options.filename || true,
            width: options.width || true,
            height: options.height || true,
            writeable: options.writeable || true,
            md5: options.md5 || true,
            path: options.path || true,
            container: options.container || true,
            security: options.security || {}
        }
    }, function(err, res, body) {
        console.log('err = '+err);
        console.log('res = '+res);
        console.log('body = '+body);
        if(err) {
            callback(err);
            return;
        }
        var returnJson;
        if(typeof(body)==='string'){
            try {
                returnJson = JSON.parse(body);
             } catch(e) {
                callback(new Error('Unknown response'), null, body);
                return;
             }
        } else {
            console.log('returnJSON');
            returnJson = body;
        }
        console.log('callbacked');
        callback(null, returnJson);
    });
};

Hi, you can try this package : https://atmospherejs.com/meteorhacks/async

Yes, I’ve looked briefly at Arunodas asyn package and see it could fit here. His approach is similar though, and Meteor.wrapAsync should really work here, so I’m still hoping to figure out why this isn’t working for me.

what about pasting these outputs when there is XY console.logs, but nothing provided to us ?

Hi, I try it and get result in error exception.

if (Meteor.isServer) {
    Meteor.methods({
        getMetadata: function (url, options) {
            try {
                check(url, String);
                var options = options || {md5 : true},
                    url = url + '/metadata'
                var getMetadataSynchronously = Meteor.wrapAsync(getInfoFilePicker);
                console.log('Begin get metadata.............')
                var result = getMetadataSynchronously(url, options);
                console.log(JSON.stringify(result));
                console.log('End.............')
            } catch (ex) {
                console.log('Exception : ', ex);
            }
        }
    });

    function getInfoFilePicker(url, options, cb) {
        var request = Meteor.npmRequire('request');
        request({url: url, qs: options}, function (err, res, body) {
            if (err)  console.log(err);
            cb(body);
        })
    }
}

In Meteor shell

> Meteor.call('getMetadata','https://www.filepicker.io/api/file/DCL5K46FS3OIxb5iuKby')

I20150901-10:14:29.585(7)? Begin get metadata.............
I20150901-10:14:30.979(7)? Exception :  { [Error: {"md5": "641ff9f723c13acbfb139f6aa33a04b4"}] stack: [Getter] }

So, Meteor.wrapAsync working but get exception…

I’m not sure what you are asking for exactly? The log file?

Interesting… looks like those getter/setter errors indicate more information can be retrieved:

I’ll have to play with this and get back to you