In my meteor.js application, I am trying to update a group's picture by using CollectionFS.
var groupimage = Images.insert(file);
Groups.update(groupId, {$set: { photo: groupimage }}, function(error) {
if (error) {
// display the error to the user
throwError(error.reason);
} else {
console.log('mongo document new');
console.log(Groups.findOne({_id:groupId}));
}
});
This does not work, it gives this error:
Exception in delivering result of invoking '/groups/update': ReferenceError: throwError is not defined
at http://localhost:3000/client/views/groups/editgroup/editgroupgeneral/editgrā¦dropzoneeditgroupgeneral.js?a1c6bb6d6c464c579ca4a82ca9f92775df17f5c5:39:21
at wrappedCallback (http://localhost:3000/packages/mongo-livedata.js?9213dc77ff40001575341a02827a8f1ed3200d98:531:9)
at null._callback (http://localhost:3000/packages/meteor.js?47d1d2b71177463dc159606cf930e44b9e3337f6:831:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3802:12)
at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3822:10)
at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:4831:9)
at onMessage (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3667:12)
at http://localhost:3000/packages/livedata.js? 32d6f3870045baedecfa7c0d90861ead2810da37:2710:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
But when I insert instead of update, everything is working perfectly. This works.
var groupimage = Images.insert(file);
Groups.insert({
name: 'My Group',
photo: groupimage
});
What is the problem with my update? Thank you.
Edit
Exception in delivering result of invoking '/groups/update': Error
at http://localhost:3000/client/views/groups/editgroup/editgroupgeneral/editgrā¦dropzoneeditgroupgeneral.js?c24e8998d12b9aaa84912c2e87ec327e47277070:39:27
at wrappedCallback (http://localhost:3000/packages/mongo-livedata.js?9213dc77ff40001575341a02827a8f1ed3200d98:531:9)
at null._callback (http://localhost:3000/packages/meteor.js?47d1d2b71177463dc159606cf930e44b9e3337f6:831:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3802:12)
at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3822:10)
at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:4831:9)
at onMessage (http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:3667:12)
at http://localhost:3000/packages/livedata.js?32d6f3870045baedecfa7c0d90861ead2810da37:2710:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
Edit 2
errorClassdetails: undefinederror: 409errorType: "Meteor.Error"message: "MongoError: not okForStorage [409]"reason: "MongoError: not okForStorage"stack: (...)get stack: function () { [native code] }arguments: nullcaller: nulllength: 0name: ""prototype: Object__proto__: function Empty() {}<function scope>set stack: function () { [native code] }__proto__: Middle
You should maybe use Meteor's error method instead:
throw new Meteor.Error(500, error.reason);
Related
I can successfully add screenshots to allure reports, but i get the following exception error:
error:
TypeError: Cannot read property 'currentStep' of undefined
at Allure.addAttachment (/Users//xxx/xxx/xxx/node_modules/allure-js-commons/index.js:86:45)
at Allure.createAttachment (/Users/xxx/xxx/xxx/node_modules/allure-js-commons/runtime.js:48:29)
at /Users/xxx/xxx/xxx/lib/class/class-name.js:30:20
at process._tickCallback (internal/process/next_tick.js:68:7)
class:
browser.takeScreenshot().then(function (png) {
allure.createAttachment(title, new Buffer(png, 'base64'));
}).catch((error: any) => console.log(error));
const allure = require('mocha-allure-reporter');
allure is a global identifier, injected by reporter to your code.
Add the following line to the top of your file to tell Typescript about it
declare const allure: any;
I think createAttachment requires a callback function and not a buffer being passed directly.
Can you try changing your code to reflect the following
browser.takeScreenshot().then(function (png) {
allure.createAttachment('Screenshot', function () {
return new Buffer(png, 'base64')
}, 'image/png')()
}).catch((error: any) => console.log(error));
I'm getting an error returned when i run a protractor test.
Here is the reference to the webelement in the directories.page.js file:
get importErrorsList(){
return element.all(by.css('[ng-if="error.error.detailMessage"]'));
}
Here is a screenshot of the webelement and it's source info:
And finally here is the step that i am using to reference the webelement, which is returning the error:
Then(/^The list of import errors contains this error message: "([^"]*)"$/, function (errorText, callback) {
browser.wait(EC.visibilityOf(importPageObj.alertMsg), timeouts.EC_TIMEOUT).then(function(){
browser.wait(() => {
//the next line causes the error
expect(directoriesPageObj.importErrorsList.getText()).to.eventually.contain(errorText).and.notify(callback);
}, timeouts.EC_TIMEOUT).then(() => {
browser.wait(EC.and(EC.visibilityOf(importPageObj.headerDropDownInWebView), EC.elementToBeClickable(importPageObj.headerDropDownInWebView)), timeouts.EC_TIMEOUT).then(() => {
callback();
});
});
});
});
could anyone help me figure out why this isn't working?
you did not initialise directoriesPageObj. So, before using it you should make:
const directoriesPageObj = new DirectoriesPageObj()
and after it you can use directoriesPageObj variable. For example:
Then(/^The list of import errors contains this error message: "([^"]*)"$/, function (errorText, callback) {
browser.wait(EC.visibilityOf(importPageObj.alertMsg), timeouts.EC_TIMEOUT).then(function(){
browser.wait(() => {
const directoriesPageObj = new DirectoriesPageObj();
expect(directoriesPageObj.importErrorsList.getText()).to.eventually.contain(errorText).and.notify(callback);
}, timeouts.EC_TIMEOUT).then(() => {
browser.wait(EC.and(EC.visibilityOf(importPageObj.headerDropDownInWebView), EC.elementToBeClickable(importPageObj.headerDropDownInWebView)), timeouts.EC_TIMEOUT).then(() => {
callback();
});
});
});
});
I upgrade sails to the #^1.0.0 version and while I'm developing an API, I wanted to use a Service but the Sails document advice to use Helper now. And I don't realy use to work with the new way to discripe helper, build script or actions.
And all the try I have mad wasn't successful.
In the following exemple..
Here is my controller call:
var ob = await ails.helpers.testy('sayHello');
res.json({ob:ob});
helper
module.exports = {
friendlyName: 'Testy',
description: 'Testy something.',
inputs: {
bla: {
type: 'string'
}
},
exits: {
success: {
}
},
fn: async function (inputs, exits) {
console.log({blabla:inputs.bla})
if(!inputs.bla) return exits.error(new Error('text not found'));
var h = "Hello "+ inputs.bla;
// All done.
return exits.success(h);
}
};
I'm getting this error
error: A hook (`helpers`) failed to load!
error:
error: Attempted to `require('*-serv\api\helpers\testy.js')`, but an error occurred:
--
D:\*-serv\api\helpers\testy.js:28
fn: async function (inputs, exits) {
^^^^^^^^
SyntaxError: Unexpected token function.......
and if I remove the "async" and the "await" form the Controller, the ob object return null and I'm having this error
WARNING: A function that was initially called over 15 seconds
ago has still not actually been executed. Any chance the
source code is missing an "await"?
To assist you in hunting this down, here is a stack trace:
```
at Object.signup [as auth/signup] (D:\*-serv\api\controllers\AuthController.js:106:26)
The first guy from the comments is right.
After removing async from fn: async function (inputs, exists) {}; you need to setup sync: true which is false by default. It is described at helpers doc page at Synchronous helpers section.
So your code should look like this
module.exports = {
friendlyName: 'Testy',
description: 'Testy something.',
sync: true, // Here is essential part
inputs: {
bla: {
type: 'string'
}
},
exits: {
success: {
}
},
fn: function (inputs, exits) {
console.log({blabla:inputs.bla})
if(!inputs.bla) return exits.error(new Error('text not found'));
var h = "Hello "+ inputs.bla;
// All done.
return exits.success(h);
}
};
From the another side, you have a problem with async/await. The top most reason for this are
Not supported Node.js version - check that you current version support it
If you use sails-hook-babel or another Babel related solution, you may miss required plugin for async/await processing
I am getting this error
TypeError: this.adapter.clients is not a function
at Namespace.clients (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/node_modules/sails-hook-sockets/node_modules/socket.io/lib/namespace.js:253:16)
at Object.addRoomMembersToRooms (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/node_modules/sails-hook-sockets/lib/sails.sockets/add-room-members-to-rooms.js:50:42)
at introduce (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/lib/hooks/pubsub/index.js:1342:23)
at wrapper [as introduce] (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/node_modules/lodash/index.js:3095:19)
at publishCreateSingle (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/lib/hooks/pubsub/index.js:1237:16)
at /Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/lib/hooks/pubsub/index.js:1069:16
at arrayEach (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/node_modules/lodash/index.js:1289:13)
at Function.<anonymous> (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/node_modules/lodash/index.js:3345:13)
at publishCreate (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/lib/hooks/pubsub/index.js:1068:11)
at wrapper [as publishCreate] (/Users/oteng/.nvm/versions/node/v4.6.0/lib/node_modules/sails/node_modules/lodash/index.js:3095:19)
when i try to publishCreate after a record creation in sailsjs
this is the create function
Tbl_Direct_Cash.create({
amount_paid: amount_paid,
payment_type: payment_type,
payment_ID: payment_ID,
tbl_user: tbl_user
}).exec(function (e, r) {
if (e) {
console.log(e);
return res.ok('TRANSACTION FAILED....TRY AGAIN');
} else {
//console.log(e);
Tbl_Direct_Cash.publishCreate({id: 40});
return res.ok('TRANSACTION SAVED');
}
});
and this is my watch method
notify: function (req, res) {
if (req.isSocket) {
Tbl_Direct_Cash.watch(req);
Tbl_Deduction.watch(req);
// Gene.watch(req);
return res.ok()
}
}
the create request is sent from a mobile app whiles the notify request
io.socket.on('connect', function () {
io.socket.get('/dashboard/notify', function (e, r) {
console.log(e, r);
});
})
is sent from the admin client
My socket.io-redis version was very old. Updating it to the latest version solved the problem
I have the following Meteor method set up inside my server directory:
// Defined in collections/collections.js
Meteor.methods({
sendEmail: function(options) {
this.unblock();
Email.send(options);
}
});
which I call like this:
// Defined in client/main.js
Meteor.call('sendEmail', {
to: 'yeahright#noneya.com', from: 'yeahright#noneya.com',
text: 'testing testing'
});
I get one error in server shell running Meteor:
Exception while invoking method 'sendEmail' { stack: 'ReferenceError: Email is not defined\n at [object
Object].Meteor.methods.sendEmail
(app/server/methods/reservations.js:82:4)\n at [object
Object].methodMap.(anonymous function)
(packages/meteorhacks_kadira/lib/hijack/wrap_session.js:164:1)\n at
maybeAuditArgumentChecks
(packages/ddp-server/livedata_server.js:1711:12)\n at
packages/ddp-server/livedata_server.js:711:19\n at [object
Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)\n
at packages/ddp-server/livedata_server.js:709:40\n at [object
Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)\n
at packages/ddp-server/livedata_server.js:707:46\n at tryCallTwo
(/Users/sltwtr/.meteor/packages/promise/.0.7.3.1y6b71x++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:45:5)\n
at doResolve
(/Users/sltwtr/.meteor/packages/promise/.0.7.3.1y6b71x++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:200:13)',I20160721-11:50:31.471(-7)?
source: 'method' }
I've added the email package using
meteor add email
What's going on? Questions like this one or this one.
Email can only be sent from the server. Meteor.methods() is being called from the server and the client
Try the following:
Meteor.methods({
sendEmail: function(options) {
if(Meteor.isServer){
this.unblock();
Email.send(options);
}
}
});