Skip to content

Instantly share code, notes, and snippets.

@atian25
Last active November 22, 2017 01:29
Show Gist options
  • Save atian25/b2c132514f1a30782de7d19f4d70f34d to your computer and use it in GitHub Desktop.
Save atian25/b2c132514f1a30782de7d19f4d70f34d to your computer and use it in GitHub Desktop.
error stack - co vs async

Intro

compare error stack between egg@1(co-base) and egg@2(async-base)

Fixture

// /app/service/test.js
class TestService extends Service {
  echo() {
    throw new Error('this is a error');
  }
}

// {2.x}/app/controller/home.js
class HomeController extends Controller {
  async index() {
    this.ctx.body = await this.ctx.service.test.echo();
  }
}

// {1.x}/app/controller/home.js
class HomeController extends Controller {
  * index() {
    this.ctx.body = yield this.ctx.service.test.echo();
  }
}

Error Stack

  • 1.x is missing service/test.js stack
  • 1.x had many boring co next/onFulfilled stack
  • 2.x is more straightforward

egg@2 - async

2017-11-22 08:43:46,599 ERROR 98784 [-/::1/-/5ms GET /] nodejs.Error: this is a error
    at TestService.echo (/Users/tz/Workspaces/eggjs/test/showcase/app/service/test.js:7:11)
    at HomeController.index (/Users/tz/Workspaces/eggjs/test/showcase/app/controller/home.js:7:49)
    at Object.callFn (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@egg-core/lib/utils/index.js:44:21)
    at Object.classControllerMiddleware (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@egg-core/lib/loader/mixin/controller.js:82:20)
    at Object.callFn (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@egg-core/lib/utils/index.js:44:21)
    at wrappedController (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@egg-core/lib/utils/router.js:317:18)
    at dispatch (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@koa-compose/index.js:44:32)
    at next (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@koa-compose/index.js:45:18)
    at /Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@koa-router/lib/router.js:345:16
    at dispatch (/Users/tz/Workspaces/eggjs/test/showcase/node_modules/[email protected]@koa-compose/index.js:44:32)

egg@1 - co yield

2017-11-22 08:43:51,772 ERROR 98685 [-/127.0.0.1/-/6ms GET /] nodejs.Error: this is a error
    at TestService.echo (/Users/tz/Workspaces/boom/egg-1.x/app/service/test.js:7:11)
    at echo.next (<anonymous>)
    at onFulfilled (/Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:65:19)
    at /Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:54:5
    at new Promise (<anonymous>)
    at Object.co (/Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:50:10)
    at Object.toPromise (/Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:118:63)
    at next (/Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:99:29)
    at onFulfilled (/Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:69:7)
    at /Users/tz/Workspaces/boom/egg-1.x/node_modules/[email protected]@co/index.js:54:5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment