Skip to content

Commit

Permalink
error-reporting: Fix report() silently failing (#2363)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
DominicKramer authored and stephenplusplus committed Jun 15, 2017
1 parent 327ed0f commit 02afcef
Show file tree
Hide file tree
Showing 28 changed files with 598 additions and 1,094 deletions.
42 changes: 42 additions & 0 deletions packages/error-reporting/src/build-stack-trace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const SRC_ROOT = __dirname;

/**
* Constructs a string representation of the stack trace at the point where
* this function was invoked. Note that the stack trace will not include any
* references to frames specific to this error-reporting library itself.
* @param {String?} message - The message that should appear as the first line
* of the stack trace. This value defaults to the empty string.
* @returns {String} - A string representation of the stack trace at the point
* where this method was invoked.
*/
function buildStackTrace(message) {
var target = {};
// Build a stack trace without the frames associated with `buildStackTrace`.
// The stack is located at `target.stack`.
Error.captureStackTrace(target, buildStackTrace);
var prefix = message ? message + '\n' : '';
return prefix + target.stack.split('\n').slice(1).filter(function(line) {
// Filter out all frames that are specific to the error-reporting library
return !line || line.indexOf(SRC_ROOT) === -1;
}).join('\n');
}

module.exports = buildStackTrace;
117 changes: 0 additions & 117 deletions packages/error-reporting/src/classes/custom-stack-trace.js

This file was deleted.

49 changes: 0 additions & 49 deletions packages/error-reporting/src/error-extractors/error.js

This file was deleted.

80 changes: 0 additions & 80 deletions packages/error-reporting/src/error-extractors/object.js

This file was deleted.

46 changes: 0 additions & 46 deletions packages/error-reporting/src/error-handlers/error.js

This file was deleted.

45 changes: 0 additions & 45 deletions packages/error-reporting/src/error-handlers/number.js

This file was deleted.

Loading

0 comments on commit 02afcef

Please sign in to comment.