Skip to content

Commit 3144fea

Browse files
DominicKramerstephenplusplus
authored andcommitted
error-reporting: Fix report() silently failing (#2363)
* error-reporting: Fix `report()` silently failing If the `report()` method is called with a number, an associated error never appears in the error reporting console, and no log message is printed to the user to indicate why the error has not appeared. * Fix linting errors * Add the new `build-stack-trace.js` file * Add more system tests for `errors.report()` * Rename errorHandlerRouter to populateErrorMessage * Rename error-router to populate-error-message * Reorganize the populate-error-message tests * Update buildStackTrace to use captureStackTrace The `Error.captureStackTrace` method is now used in the `buildStackTrace` function to create a stack trace. * Simplify the system tests The code for verifiying that stack traces don't contain error-reporting specific frames has been consolidated into a single location. * Consolidate code in populate-error-message.js * Make the `buildStackTrace` more robust In particular, the `buildStackTrace` was updated to ensure that no error-reporting specific frames are included in the built stack trace. In addition, the system-tests have been updated to ensure error-reporting related frames, and only those frames, are removed from the built stack trace.
1 parent 4029a11 commit 3144fea

28 files changed

+598
-1094
lines changed

src/build-stack-trace.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2017 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const SRC_ROOT = __dirname;
20+
21+
/**
22+
* Constructs a string representation of the stack trace at the point where
23+
* this function was invoked. Note that the stack trace will not include any
24+
* references to frames specific to this error-reporting library itself.
25+
* @param {String?} message - The message that should appear as the first line
26+
* of the stack trace. This value defaults to the empty string.
27+
* @returns {String} - A string representation of the stack trace at the point
28+
* where this method was invoked.
29+
*/
30+
function buildStackTrace(message) {
31+
var target = {};
32+
// Build a stack trace without the frames associated with `buildStackTrace`.
33+
// The stack is located at `target.stack`.
34+
Error.captureStackTrace(target, buildStackTrace);
35+
var prefix = message ? message + '\n' : '';
36+
return prefix + target.stack.split('\n').slice(1).filter(function(line) {
37+
// Filter out all frames that are specific to the error-reporting library
38+
return !line || line.indexOf(SRC_ROOT) === -1;
39+
}).join('\n');
40+
}
41+
42+
module.exports = buildStackTrace;

src/classes/custom-stack-trace.js

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/error-extractors/error.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/error-extractors/object.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/error-handlers/error.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/error-handlers/number.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)