senecajs / seneca

A microservices toolkit for Node.js.
http://senecajs.org
MIT License
3.96k stars 314 forks source link

Error: gate-executor question #461

Closed danswater closed 8 years ago

danswater commented 8 years ago

What I'm trying to do is I want to create a service that will upload some images to cloudinary, cloudinary provides an SDK for uploading images to their server.

So this is what my code looks like

const cloudinary = require( 'cloudinary' );

function fileManager ( options ) {
    let seneca = this;
    let plugin = 'fileManager';

    seneca.add( 'init:files', init );
    seneca.add( 'role:files,cmd:upload', cmdUpload );

    function init () {
        cloudinary.config( { ... } );
    }

    function cmdUpload ( msg, reply ) {
        cloudinary.uploader.upload( msg.data.StringImage, function ( res ) {
            reply( null, res );
        } );
    }

    return {
        'name' : plugin
    }
}

module.exports = fileManager;

And I tried to call this service for testing

const assert = require( 'assert' );
const seneca = require( 'seneca' )();

seneca
    .use( 'entity' )
    .use( require( './file-manager' ) )
    .error( assert.fail );

createFile();

function createFile () {
    let data = '<some-base64-image-string>';

    seneca.act( { 'role' : 'files', 'cmd' : 'upload', 'data' : { 'StringName' : data } }, function ( err, file ) {
        if ( err ) return console.log( err );

        // assertion
        console.log( file );
    } );
}

Everytime I run the code above seneca always throw this error.

2016-08-03T09:02:29.763Z 9xgvkx0rlzyq/1470214949720/25520/- INFO    hello   Seneca/2.1.0/9xgvkx0rlzyq/1470214949720/25520/- 
2016-08-03T09:02:30.148Z 9xgvkx0rlzyq/1470214949720/25520/- INFO    listen  {type:tcp,host:localhost,timeout:5000}  
2016-08-03T09:02:30.241Z 9xgvkx0rlzyq/1470214949720/25520/- ERROR   act fileManager OUT     cmd:upload,role:files   90  {role:files,cmd:upload,data:{StringName:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgID ENTRY   (2skpbdvdlz96)  -   seneca: Action cmd:upload,role:files failed: gate-executor: action-execute. act_execute {id:a5flf8zjhysq/1tm2ws1dxpyp,gate:false,ungate:false,desc:null,time:{start:1470214950235},message:gate-executo Error: gate-executor: action-execute
    at errormaker (/home/francis/projects/learn-seneca/node_modules/eraro/eraro.js:94:15)
    at Immediate._onImmediate (/home/francis/projects/learn-seneca/node_modules/gate-executor/gate-executor.js:171:18)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)   
2016-08-03T09:02:30.243Z 9xgvkx0rlzyq/1470214949720/25520/- FATAL   sys seneca  2.1.0   9xgvkx0rlzyq/1470214949720/25520/-      { Error: gate-executor: action-execute
    at errormaker (/home/francis/projects/learn-seneca/node_modules/eraro/eraro.js:94:15) undefined undefined   
Seneca Panic
============

AssertionError: { AssertionError: { Error: gate-executor: action-execute
    at errormaker (/home/francis/projects/learn-seneca/node_modules/era undefined undefined
    at Seneca.die (/home/francis/projects/learn-seneca/node_modules/seneca/lib/common.js:299:23)
    at emitOne (events.js:96:13)
    at Seneca.emit (events.js:188:7)
    at act_done (/home/francis/projects/learn-seneca/node_modules/seneca/seneca.js:1288:18)
    at Immediate._onImmediate (/home/francis/projects/learn-seneca/node_modules/gate-executor/gate-executor.js:173:11)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)

Original Error:
AssertionError: { Error: gate-executor: action-execute
    at errormaker (/home/francis/projects/learn-seneca/node_modules/eraro/eraro.js:94:15) undefined undefined
    at act_error (/home/francis/projects/learn-seneca/node_modules/seneca/seneca.js:1349:32)
    at act_done (/home/francis/projects/learn-seneca/node_modules/seneca/seneca.js:1230:21)
    at Immediate._onImmediate (/home/francis/projects/learn-seneca/node_modules/gate-executor/gate-executor.js:173:11)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)

Can someone point me out what is wrong with this one?

Thanks

indr commented 8 years ago

Do you call the callback in your init action? Init actions have the same signature like every action afaik. Also try to wrap you call of createFile in seneca.ready(function (err) { ... }.

danswater commented 8 years ago

I updated the init action

    function init ( msg, reply ) {
        cloudinary.config( { ... } );
        reply();
    }

and also invoking createFile inside seneca.ready but still I got the same error.

I suspect that this line of code seneca throws an error

        cloudinary.uploader.upload( msg.data.StringImage, function ( res ) {
            reply( null, res );
        } );

because when I try to remove the cloudinary and calling reply( null, { 'res' : 'testing' ) instead it actually works fine.

indr commented 8 years ago

And you are sure your init action gets called? Because the plugin name differs. Try this seneca.add( {init:plugin}, init );

danswater commented 8 years ago

@indr , Thank you for figuring out my mistake! :)

I initially name my plugin to files and then eventually rename it to fileManager but I forgot to renamed this part seneca.add( {init:files}, init ).

indr commented 8 years ago

@danswater My pleasure :smile:

danswater commented 8 years ago

I'm closing this issue now. Seneca rocks!