Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
feat(error): can config how to load blacklist zone stack frames
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Apr 11, 2018
1 parent 1ba8519 commit a50debd
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 117 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ script:
- node_modules/.bin/karma start karma-build-sauce-mocha.conf.js --single-run
- node_modules/.bin/karma start karma-dist-sauce-selenium3-jasmine.conf.js --single-run
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run --errorpolicy=disable
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run --errorpolicy=lazy
- node_modules/.bin/gulp test/node
- node_modules/.bin/gulp test/node -no-patch-clock
- node_modules/.bin/gulp test/bluebird
- node_modules/.bin/gulp test/node/disableerror
- node_modules/.bin/gulp test/node/lazyerror
- node simple-server.js 2>&1> server.log&
- node ./test/webdriver/test.sauce.js
- yarn add jasmine@3.0.0 jasmine-core@3.0.0 mocha@5.0.1
Expand Down
51 changes: 51 additions & 0 deletions MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,57 @@ you can do like this.
<script src="../dist/zone.js"></script>
```

- Error

By default, `zone.js/dist/zone-error` will not be loaded for performance concern.
This package will provide following functionality.

1. Error inherit: handle `extend Error` issue.
```
class MyError extends Error {}
const myError = new MyError();
console.log('is MyError instanceof Error', (myError instanceof Error));
```

without `zone-error` patch, the example above will output `false`, with the patch, the reuslt will be `true`.

2. BlacklistZoneStackFrames: remove zone.js stack from `stackTrace`, and add `zone` information. Without this patch, a lot of `zone.js` invocation stack will be shown
in stack frames.

```
at zone.run (polyfill.bundle.js: 3424)
at zoneDelegate.invokeTask (polyfill.bundle.js: 3424)
at zoneDelegate.runTask (polyfill.bundle.js: 3424)
at zone.drainMicroTaskQueue (polyfill.bundle.js: 3424)
at a.b.c (vendor.bundle.js: 12345 <angular>)
at d.e.f (main.bundle.js: 23456)
```

with this patch, those zone frames will be removed,
and the zone information `<angular>/<root>` will be added

```
at a.b.c (vendor.bundle.js: 12345 <angular>)
at d.e.f (main.bundle.js: 23456 <root>)
```

The second feature will slow down the `Error` performance, so `zone.js` provide a flag to let you be able to control the behavior.
The flag is `__Zone_Error_BlacklistedStackFrames_policy`. And the available options is:

1. default: this is the default one, if you load `zone.js/dist/zone-error` without
setting the flag, `default` will be used, and `BlackListStackFrames` will be available
when `new Error()`, you can get a `error.stack` which is `zone stack free`. But this
will slow down `new Error()` a little bit.

2. disable: this will disable `BlackListZoneStackFrame` feature, and if you load
`zone.js/dist/zone-error`, you will only get a `wrapped Error` which can handle
`Error inherit` issue.

3. lazy: this is a feature to let you be able to get `BlackListZoneStackFrame` feature,
but not impact performance. But as a trade off, you can't get the `zone free stack
frames` by access `error.stack`. You can only get it by access `error.zoneAwareStack`.


- Angular(2+)

Angular uses zone.js to manage async operations and decide when to perform change detection. Thus, in Angular,
Expand Down
12 changes: 12 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ gulp.task('test/bluebird', ['compile-node'], function(cb) {
nodeTest(specFiles, cb);
});

gulp.task('test/node/disableerror', ['compile-node'], function(cb) {
process.env.errorpolicy = 'disable';
var specFiles = ['build/test/node_error_entry_point.js'];
nodeTest(specFiles, cb);
});

gulp.task('test/node/lazyerror', ['compile-node'], function(cb) {
process.env.errorpolicy = 'lazy';
var specFiles = ['build/test/node_error_entry_point.js'];
nodeTest(specFiles, cb);
});

// Check the coding standards and programming errors
gulp.task('lint', () => {
const tslint = require('gulp-tslint');
Expand Down
29 changes: 12 additions & 17 deletions karma-base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,35 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
module.exports = function(config) {
config.set({
basePath: '',
client: {errorpolicy: config.errorpolicy},
files: [
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs/dist/system-polyfills.js', 'node_modules/systemjs/dist/system.src.js',
'node_modules/whatwg-fetch/fetch.js',
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false},
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},
{pattern: 'build/**/*.js', watched: true, served: true, included: false}
],

plugins: [
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-chrome-launcher'), require('karma-firefox-launcher'),
require('karma-sourcemap-loader')
],

preprocessors: {
'**/*.js': ['sourcemap']
},
preprocessors: {'**/*.js': ['sourcemap']},

exclude: [
'test/microtasks.spec.ts'
],
exclude: ['test/microtasks.spec.ts'],

reporters: ['progress'],

//port: 9876,
// port: 9876,
colors: true,

logLevel: config.LOG_INFO,
Expand Down
3 changes: 1 addition & 2 deletions karma-build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
module.exports = function(config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('build/test/test_fake_polyfill.js');
config.files.push('build/lib/zone.js');
config.files.push('build/lib/common/promise.js');
config.files.push('build/lib/common/error-rewrite.js');
config.files.push('build/test/main.js');
};
Loading

0 comments on commit a50debd

Please sign in to comment.