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

Cannot read property '1' of null #41

Open
abenhamdine opened this issue Sep 8, 2017 · 2 comments
Open

Cannot read property '1' of null #41

abenhamdine opened this issue Sep 8, 2017 · 2 comments

Comments

@abenhamdine
Copy link

abenhamdine commented Sep 8, 2017

Hello Juris,

For the fist time (I use Ext.Direct since 2 years), I run into this strange error when the api is called, after having added a new module in direct/ folder :

Fri, 08 Sep 2017 09:13:48 GMT : exception non gérée récupérée dans server.js
Cannot read property '1' of null
TypeError: Cannot read property '1' of null
    at API.reflection (C:\node-projects\payroll-app\node_modules\extdirect\lib\api.js:196:28)
    at C:\node-projects\payroll-app\node_modules\extdirect\lib\api.js:85:37
    at iterate (C:\node-projects\payroll-app\node_modules\extdirect\lib\api.js:224:35)
    at C:\node-projects\payroll-app\node_modules\extdirect\lib\api.js:243:25
    at FSReqWrap.oncomplete (fs.js:153:5)

the culprit is argDecl there :

nodejs.extdirect/lib/api.js

Lines 189 to 192 in f00a4b3

fnText = fnStr.replace(STRIP_COMMENTS, '');
argDecl = fnText.match(config.ES6 ? ES6_FN_ARGS : FN_ARGS);
var r = argDecl[1].split(FN_ARG_SPLIT);

I don't understand the reason, because this module is seemingly written like my other direct modules :

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("source-map-support/register");
const async = require("async");
const tools = require("../../tools");
const selectPERIA_1 = require("../../payrollEngine/selectPERIA");
const getPosConv_1 = require("../../payrollEngine/getPosConv");
const db_1 = require("../../db");
const sql_template_strings_2 = require("sql-template-strings");
const self = {
    get: function (params, externalCallback) {
        //@meta _config _appSessionId
        async.waterfall([
            (cb) => self.selectData(params, cb)
        ], (err, rows) => {
            if (err) {
                tools.logError("settingsPortalEmployee.get() : erreur : ", err);
                return externalCallback({
                    message: err.message,
                    where: err.message
                });
            }
            return externalCallback(null, {
                success: true,
                data: rows
            });
        });
    },
    selectData: function (params, done) {
        async.waterfall([
            (cb) => {
                db_1.default.connect((errConnect, client) => {
                    return cb(errConnect, client);
                });
            },
            (client, cb) => self.selectCnt(params.uti_id, client, cb),
            (client, cnt, cb) => {
                selectPERIA_1.default.get(client, cnt, (errPeria, dataPeria) => {
                    return cb(errPeria, client, cnt, dataPeria);
                });
            },
            (client, cnt, dataPeria, cb) => {
                getPosConv_1.default.process(client, cnt, cnt.peri_anneemoi, (errPosConv, posConv) => {
                    return cb(errPosConv, client, cnt, dataPeria, posConv);
                });
            }
        ], function (err, results) {
            if (err) {
                return done(err);
            }
            return done(null, results);
        });
    },
    /**
     * Renvoit le dernier contrat du salarié correspondant à l'utilisateur
     */
    selectCnt: (uti_id, client, done) => {
        const sql = sql_template_strings_2.default `
            SELECT
                cnt.cnt_id,
                sal.pad_id,
                cnt.ncnt_id,
                cnt.semp_id,
                cnt.eta_id,
                cnt.cnt_fin_date,
                ppa_cour.peri_anneemois
            FROM
                pay_contrat_cnt cnt INNER JOIN pay_salarie_sal sal ON cnt.sal_id = sal.sal_id
                INNER JOIN usr_utilisateur_uti uti ON sal.sal_id = uti.sal_id
                INNER JOIN pay_lotdepaye_lot lot ON cnt.lot_id = lot.lot_id
                LEFT OUTER JOIN pay_periodepaye_ppa ppa_cour ON lot.ppa_id_courante = ppa_cour.ppa_id
            WHERE
                uti.uti_id = ${uti_id}
            ORDER BY
                cnt.cnt_fin_date DESC
        `;
        client.query(sql, (err, result) => {
            if (err) {
                return done(err);
            }
            return done(null, client, result.rows[0]);
        });
    }
};
module.exports = self;
//# sourceMappingURL=settingsPortalEmployee.js.map

any idea of the cause ?

@abenhamdine
Copy link
Author

abenhamdine commented Sep 8, 2017

Ah I found the cause, it was the arrow function

 selectCnt: (uti_id, client, done) => {
...
}

I think ES6 option in config should be true by default, (and why is it an option after all ? are there any inconvienents to use it ?).

Print a friendly warning to the user when argDecl is undefined would be nice too (I wil send a PR if I have some time).

@abenhamdine
Copy link
Author

For future readers: this error also occurs if you use ES6 shorthand method name (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions)

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

1 participant