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

Log Server Errors #695

Merged
merged 6 commits into from
Feb 9, 2016
Merged

Log Server Errors #695

merged 6 commits into from
Feb 9, 2016

Conversation

campersau
Copy link
Collaborator

Some recent bugreports (#689, #679) contain client- and serverside logs but they do not contain any useful errors.

The main reasons for this are:

  1. JavaScript Errors are not serializable with JSON.stringify by default
  2. The jsonResultOrFailProm does not log anything in case of an error

The first commit fixes point 1 by implementing toJSON on Error.
Before an empty object {} would be returned now the response includes all fields of an Error object such as message and stack:

{"stack":"Error: Test\n    at exports.parseGitSubmodule (P:\\ungit\\source\\git-parser.js:217:19)\n    at tryCatcher (P:\\ungit\\node_modules\\bluebird\\js\\release\\util.js:11:23)\n    at Promise._settlePromiseFromHandler (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:491:31)\n    at Promise._settlePromise (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:548:18)\n    at Promise._settlePromise0 (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:593:10)\n    at Promise._settlePromises (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:676:18)\n    at Promise._fulfill (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:617:18)\n    at Promise._settlePromise (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:561:21)\n    at Promise._settlePromise0 (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:593:10)\n    at Promise._settlePromises (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:676:18)\n    at Promise._fulfill (P:\\ungit\\node_modules\\bluebird\\js\\release\\promise.js:617:18)\n    at P:\\ungit\\node_modules\\bluebird\\js\\release\\nodeback.js:42:21\n    at fs.js:334:14\n    at P:\\ungit\\node_modules\\npm-registry-client\\node_modules\\graceful-fs\\graceful-fs.js:42:10\n    at FSReqWrap.oncomplete (fs.js:95:15)","message":"Test"}

So the errors are visible in the network panel:
image


The second commit logs the information provided by commit 1 in the client console.
image


The third commit logs errors in the server console and fixes point 2.

2016-02-05T20:12:23.945Z - info: GET /api/submodules?path=P%3A%5Cvstup&socketId=3
Unhandled error: Test
ReferenceError: Test
    at exports.parseGitSubmodule (P:\ungit\source\git-parser.js:217:19)
    at tryCatcher (P:\ungit\node_modules\bluebird\js\release\util.js:11:23)
    at Promise._settlePromiseFromHandler (P:\ungit\node_modules\bluebird\js\release\promise.js:491:31)
    at Promise._settlePromise (P:\ungit\node_modules\bluebird\js\release\promise.js:548:18)
    at Promise._settlePromise0 (P:\ungit\node_modules\bluebird\js\release\promise.js:593:10)
    at Promise._settlePromises (P:\ungit\node_modules\bluebird\js\release\promise.js:676:18)
    at Promise._fulfill (P:\ungit\node_modules\bluebird\js\release\promise.js:617:18)
    at Promise._settlePromise (P:\ungit\node_modules\bluebird\js\release\promise.js:561:21)
    at Promise._settlePromise0 (P:\ungit\node_modules\bluebird\js\release\promise.js:593:10)
    at Promise._settlePromises (P:\ungit\node_modules\bluebird\js\release\promise.js:676:18)
    at Promise._fulfill (P:\ungit\node_modules\bluebird\js\release\promise.js:617:18)
    at P:\ungit\node_modules\bluebird\js\release\nodeback.js:42:21
    at fs.js:334:14
    at P:\ungit\node_modules\npm-registry-client\node_modules\graceful-fs\graceful-fs.js:42:10
    at FSReqWrap.oncomplete (fs.js:95:15)

Error responses now include all properties from the Error object. Such as `message` and `stack`.
@campersau
Copy link
Collaborator Author

This also exposes a lot of Unhandled errors in the tests see https://travis-ci.org/FredrikNoren/ungit/jobs/107326833
But tests are passing anyway.

@jung-kim
Copy link
Collaborator

jung-kim commented Feb 5, 2016

👍 * 💯

This will most definitely help us with debugging! While we are being clever, can we be more clever by doing below as well? with below code we can reduce https://github.com/campersau/ungit/blob/server_errors/source/git-api.js#L114-L120 to console.error(err); right?

Object.defineProperty(Error.prototype, 'toString', {
  value: function() {
    return 'Message: ' + this.message + '\n' + this.stack;
  }
});

@campersau
Copy link
Collaborator Author

@codingtwinky No, this somehow does not work. Maybe some Errors are overriding the default toString implementation.

For example the TypeError you see here would only be traced like this:

    V quickstatus should say inited in inited directory (41ms)
[TypeError: Cannot read property 'indexOf' of undefined]
    V commit should fail on when there's no files to commit

@campersau
Copy link
Collaborator Author

Sorry, it would have worked if the code was in a file which would be loaded everywhere. Looks like the tests mentioned do not require source/server.js to be loaded.

Should I move the Object.defineProperty code to git-promise.js and add your toString override?

@jung-kim
Copy link
Collaborator

jung-kim commented Feb 7, 2016

Hmmm... I'm wondering if including in .../source/config.js as it would get used via both front and back.

Would that be a better place? if not, I think git-promise is a good place.

also adding `Error.prototype.toString` override
@campersau
Copy link
Collaborator Author

I moved the code to config.js and also added your toString override.

@FredrikNoren
Copy link
Owner

👍 this is awesome!

@campersau
Copy link
Collaborator Author

What happend here?

Looks like Node.js 0.10 does not like the toString override? Without that it worked: https://travis-ci.org/FredrikNoren/ungit/jobs/107326829#L995

it does not work in Node.js 0.10
@jung-kim
Copy link
Collaborator

jung-kim commented Feb 9, 2016

I can reproduce this error in node/0.10.41. It seems like implementation of Error#stack is calling or referencing to Error#toString() and continuously calls each other... Which is really interesting as stack is a property.

This seems to be fixed in later version and I guess I really shouldn't mess with existing core implementations.... :P

> var n = 0;
undefined
> Object.defineProperty(Error.prototype, 'toString', {
...   value: function() {
.....     if (n++ > 5) return 'ugh oh';
.....     return this.stack;
.....   }
... });
[undefined]
> var e = new Error('abc')
ugh oh
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    [TL;DR;]
> e.stack
ugh oh
    at repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:203:10)
    at Interface._line (readline.js:532:8)
    at Interface._ttyWrite (readline.js:761:14)
    at ReadStream.onkeypress (readline.js:100:10)
    at ReadStream.emit (events.js:98:17)
    at emitKey (readline.js:1096:12)
> 

jung-kim added a commit that referenced this pull request Feb 9, 2016
@jung-kim jung-kim merged commit a176a00 into FredrikNoren:master Feb 9, 2016
@campersau campersau deleted the server_errors branch February 9, 2016 05:31
@jung-kim jung-kim mentioned this pull request Feb 11, 2016
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

Successfully merging this pull request may close these issues.

3 participants