openfisca / legislation-explorer

Explore legislation formulas and parameters.
https://legislation.demo.openfisca.org
GNU Affero General Public License v3.0
26 stars 12 forks source link

Replace errors emailing by logging #93

Closed michelbl closed 7 years ago

michelbl commented 7 years ago

Connected to #86.

To test the logging, I added some code intended to fail here : https://github.com/openfisca/legislation-explorer/blob/master/src/server/render.jsx#L15 :

    var a
    a.b

Console output is :

[0] Server listening at http://localhost:2030/
[0] error: Error on request GET /
[0] TypeError: Cannot read property 'b' of undefined
[0]     at /data/projects/openfisca/legislation-explorer/src/server/render.jsx:16:5
[0]     at Layer.handle [as handle_request] (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/layer.js:95:5)
[0]     at trim_prefix (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:317:13)
[0]     at /data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:284:7
[0]     at Function.process_params (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:335:12)
[0]     at next (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:275:10)
[0]     at SendStream.error (/data/projects/openfisca/legislation-explorer/node_modules/serve-static/index.js:121:7)
[0]     at emitOne (events.js:96:13)
[0]     at SendStream.emit (events.js:188:7)
[0]     at SendStream.error (/data/projects/openfisca/legislation-explorer/node_modules/send/index.js:282:17)
[0] TypeError: Cannot read property 'b' of undefined
[0]     at /data/projects/openfisca/legislation-explorer/src/server/render.jsx:16:5
[0]     at Layer.handle [as handle_request] (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/layer.js:95:5)
[0]     at trim_prefix (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:317:13)
[0]     at /data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:284:7
[0]     at Function.process_params (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:335:12)
[0]     at next (/data/projects/openfisca/legislation-explorer/node_modules/express/lib/router/index.js:275:10)
[0]     at SendStream.error (/data/projects/openfisca/legislation-explorer/node_modules/serve-static/index.js:121:7)
[0]     at emitOne (events.js:96:13)
[0]     at SendStream.emit (events.js:188:7)
[0]     at SendStream.error (/data/projects/openfisca/legislation-explorer/node_modules/send/index.js:282:17)

The stack is logged twice.

Is there a way to automate this test ?

fpagnoux commented 7 years ago

Is there a way to add the date and time the error happened ? This is very useful information when production bugs appears 😄

michelbl commented 7 years ago

It incited me to add configuration for winston.

michelbl commented 7 years ago

I still have errors about json parsing :

ERROR in ./~/winston/package.json
[1] Module parse failed: /data/projects/openfisca/legislation-explorer/node_modules/winston/package.json Unexpected token (2:9)
[1] You may need an appropriate loader to handle this file type.
[1] SyntaxError: Unexpected token (2:9)
MattiSG commented 7 years ago

I still have errors about json parsing

This could be linked to ES2015 imports: you are calling import rather than require, and that call is transpiled. You can try the solution presented in https://github.com/winstonjs/winston/issues/801, or try to replace import winston from "winston" to let winston = require('winston').

MattiSG commented 7 years ago

Is there a way to automate this test ?

Yes, but that means adding a backend testing stack for it. That would be welcome. See this example.

michelbl commented 7 years ago

This could be linked to ES2015 imports: you are calling import rather than require, and that call is transpiled. You can try the solution presented in winstonjs/winston#801, or try to replace import winston from "winston" to let winston = require('winston').

I tried const winston = require('winston'), import * as winston from 'winston', let winston = require('winston'), import winston from "winston" and none of them work.

fpagnoux commented 7 years ago

Seems to work :

[0] 2017-06-15T14:17:15.553Z - error: GET / 
[0] TypeError: Cannot read property 'b' of undefined
[0]     at /Users/fpagnoux/dev/openfisca/legislation-explorer/src/server/render.jsx:16:5
...
fpagnoux commented 7 years ago

@MattiSG is this GTM for you ?

MattiSG commented 7 years ago

Wait 5 minutes, I'll handle changes.

MattiSG commented 7 years ago

Ok, error page usability improved.