node4good / formage

Bootstraped Admin GUI addon for mongoose, jugglingdb, or just as a form generator
formage.io
MIT License
185 stars 55 forks source link

Error while deleting an object #122

Open marekrogala opened 10 years ago

marekrogala commented 10 years ago

Hi,

We get a strange error, which looks like an internal error, while deleting and object with Formage.

Here's what I do:

  1. Login to Formage using valid user and password
  2. Choose object type, in our case for example Users
  3. Choose an object, i .e. one of the users
  4. Click delete and confirm
  5. A message "error" with no additional details is displayed (screenshots attached below). Server output is:
[18:16:51] [server] error: TypeError: Cannot read property 'map' of undefined
  at _map (/home/filip/Projects/x/node_modules/formage/node_modules/async/lib/async.js:54:16)
  at _asyncMap (/home/filip/Projects/x/node_modules/formage/node_modules/async/lib/async.js:237:15)
  at Object.map (/home/filip/Projects/x/node_modules/formage/node_modules/async/lib/async.js:219:23)
  at Object.modelConfig.actions.push.func (/home/filip/Projects/x/node_modules/formage/lib/registry.js:220:19)
  at actionDocuments (/home/filip/Projects/x/node_modules/formage/lib/controllers.js:219:40)
  at Layer.handle [as handle_request] (/home/filip/Projects/x/node_modules/formage/node_modules/express/lib/router/layer.js:76:5)
  at next (/home/filip/Projects/x/node_modules/formage/node_modules/express/lib/router/route.js:100:13)
  at afterParseSession (/home/filip/Projects/x/node_modules/formage/lib/controllers.js:531:32)
  at in_the_handler (/home/filip/Projects/x/node_modules/formage/node_modules/mpromise/lib/promise.js:238:18)
  at process._tickCallback (node.js:419:13)

The error occurs for any of the models.

We're stuck with this error and will appreciate your help. How can we eliminate this error? We have noticed that Formage uses socket.io internally. We have our own socket.io server running on the same machine -- can this be the reason of the problem?

Environment

  1. Mongo server is set up locally on the machine
  2. Formage is set up using:
import formage = require("formage");
import express = require("express");
var options = {
            title: "Admin Panel",
            root: "/admin",
            default_section: "main",
            username: "admin",
            password: "password",
            admin_users_gui: true
};
formage.init(app, express, app.getModels(), options);
// getModels() is our mix-in which returns the models in the app
  1. Example schema: var documentSchema = new mongoose.Schema({ definitionId: { type: Number }, userName: { type: String, index: true }, state: { type: Number, enum: [DocumentState.Started, DocumentState.Finished] }, data: mongoose.Schema.Types.Mixed });

    Attachments

  2. The "are you sure" question displayed correctly: a8974db2-4305-11e4-9949-bdf8b2a255a4
  3. The error message after confirming: ab650c3c-4305-11e4-9204-021c6bc2d399
DamianRodziewicz commented 10 years ago

Body-parser changes 'ids' to 'ids[]' and if there is only one element the type of 'ids[]' is string. I wrote a quick workaround for this problem (in formage/lib/controllers.ts):

var modelName = req.params.modelName,
    actionId = req.params['actionId'],
    ids = ('ids' in req.body) ? req.body.ids : req.body['ids[]'],
    model = registry.models[modelName];

ids = (typeof(ids) === 'string') ? [ ids ] : ids;
bstahlhood commented 9 years ago

I am getting the exact same error when trying to delete models.

alonronin commented 9 years ago

:+1:

Cannot read property 'map' of undefined

TypeError: Cannot read property 'map' of undefined
    at _map (f:\www\eliluski\node_modules\formage\node_modules\async\lib\async.js:54:16)
    at _asyncMap (f:\www\eliluski\node_modules\formage\node_modules\async\lib\async.js:237:15)
    at Object.doParallel [as map] (f:\www\eliluski\node_modules\formage\node_modules\async\lib\async.js:219:23)
    at Object.modelConfig.actions.push.func (f:\www\eliluski\node_modules\formage\lib\registry.js:220:19)
    at actionDocuments (f:\www\eliluski\node_modules\formage\lib\controllers.js:219:40)
    at Layer.handle [as handle_request] (f:\www\eliluski\node_modules\formage\node_modules\express\lib\router\layer.js:76:5)
    at next (f:\www\eliluski\node_modules\formage\node_modules\express\lib\router\route.js:100:13)
    at afterParseSession (f:\www\eliluski\node_modules\formage\lib\controllers.js:531:32)
    at newTickHandler (f:\www\eliluski\node_modules\formage\node_modules\mpromise\lib\promise.js:234:18)
    at process._tickCallback (node.js:355:11)

model:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Types = Schema.Types;

var schema = new Schema({
    email: { type: String, unique: true },
    password: { type: String }
});

schema.methods.toString = function(){
    return this.email;
};

module.exports = schema;

express app:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieSession = require('cookie-session');
var bodyParser = require('body-parser');
var models = require('./models');
var mongoose = require('mongoose');
var formage = require('formage');

var routes = require('./routes/index');

var app = express();

app.set('site', 'My Site');
app.set('secret', 'secret');
app.set('mongo', process.env.MONGOLAB_URI);

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');

// uncomment after placing your favicon in /public
// app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieSession({secret: app.get('secret'), expires: 604800000}));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);

formage.init(app, models, {
    title: app.get('site') + ' Admin',
    username: process.env.ADMIN_PASSWORD || 'admin',
    password: process.env.ADMIN_USER || 'admin',
    default_section: 'Configurations',
    root: '/admin'
});

// catch 404 and forward to error handler
app.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function (err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});

mongoose.connect(app.get('mongo'));

module.exports = app;

@refack welcome back :smile:

refack commented 9 years ago

So much Balagan

On Tue, Jun 23, 2015 at 5:02 PM Alon Valadji notifications@github.com wrote:

[image: :+1:]

Cannot read property 'map' of undefined

TypeError: Cannot read property 'map' of undefined at _map (f:\www\eliluski\node_modules\formage\node_modules\async\lib\async.js:54:16) at _asyncMap (f:\www\eliluski\node_modules\formage\node_modules\async\lib\async.js:237:15) at Object.doParallel as map at Object.modelConfig.actions.push.func (f:\www\eliluski\node_modules\formage\lib\registry.js:220:19) at actionDocuments (f:\www\eliluski\node_modules\formage\lib\controllers.js:219:40) at Layer.handle as handle_request at next (f:\www\eliluski\node_modules\formage\node_modules\express\lib\router\route.js:100:13) at afterParseSession (f:\www\eliluski\node_modules\formage\lib\controllers.js:531:32) at newTickHandler (f:\www\eliluski\node_modules\formage\node_modules\mpromise\lib\promise.js:234:18) at process._tickCallback (node.js:355:11)

model:

var mongoose = require('mongoose');var Schema = mongoose.Schema;var Types = Schema.Types; var schema = new Schema({ email: { type: String, unique: true }, password: { type: String } }); schema.methods.toString = function(){ return this.email; }; module.exports = schema;

express app:

var express = require('express');var path = require('path');var favicon = require('serve-favicon');var logger = require('morgan');var cookieSession = require('cookie-session');var bodyParser = require('body-parser');var models = require('./models');var mongoose = require('mongoose');var formage = require('formage'); var routes = require('./routes/index'); var app = express();

app.set('site', 'My Site'); app.set('secret', 'secret'); app.set('mongo', process.env.MONGOLAB_URI); // view engine setup app.set('views', path.join(dirname, 'views')); app.set('view engine', 'hjs'); // uncomment after placing your favicon in /public// app.use(favicon(dirname + '/public/favicon.ico')); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false})); app.use(cookieSession({secret: app.get('secret'), expires: 604800000})); app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);

formage.init(app, models, { title: app.get('site') + ' Admin', username: process.env.ADMIN_PASSWORD || 'admin', password: process.env.ADMIN_USER || 'admin', default_section: 'Configurations', root: '/admin' }); // catch 404 and forward to error handler app.use(function (req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); // error handlers // development error handler// will print stacktraceif (app.get('env') === 'development') { app.use(function (err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: err }); }); } // production error handler// no stacktraces leaked to user app.use(function (err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: {} }); });

mongoose.connect(app.get('mongo')); module.exports = app;

@refack https://github.com/refack welcome back [image: :smile:]

— Reply to this email directly or view it on GitHub https://github.com/TheNodeILs/formage/issues/122#issuecomment-114641040.

robbyoconnor commented 7 years ago

Issue here as well.

refack commented 7 years ago

Looking into it. @robbyoconnor Which ver 2.8.2 or 3.2.21? (and which express mongoose?)

robbyoconnor commented 7 years ago

@refack -- formage 3.3.0, express 4.14.1, mongoose 4.8.2

robbyoconnor commented 7 years ago

See https://github.com/node4good/formage/pull/140 for a fix. Thank you @DamianRodziewicz!