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

Document how to enable source map support #1579

Closed
otterley opened this issue Jan 20, 2019 · 1 comment · Fixed by #1581
Closed

Document how to enable source map support #1579

otterley opened this issue Jan 20, 2019 · 1 comment · Fixed by #1581
Labels
feature-request A feature should be added or improved.

Comments

@otterley
Copy link
Contributor

otterley commented Jan 20, 2019

Currently, when an uncaught exception is encountered when running cdk, the backtrace is of the compiled Javascript code, not the TypeScript source. For example:

 cdk synth
/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.js:305
            throw new Error(`There is already a Construct with name '${childName}' in ${this.toString()}`);
            ^

Error: There is already a Construct with name 'Snapshot Complete' in [object Object]
    at ConstructNode.addChild (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.js:305:19)
    at new ConstructNode (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.js:37:24)
    at new Construct (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.js:417:21)
    at new State (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/aws-stepfunctions/lib/states/state.js:10:9)
    at new Task (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/aws-stepfunctions/lib/states/task.js:14:9)
    at new Snapshotter (/Users/otterley/src/common/snapshotter/lib/index.js:50:30)
    at new DevEnvStack (/Users/otterley/src/aem/dev-env/lib/dev-env-stack.js:17:9)
    at Object.<anonymous> (/Users/otterley/src/aem/dev-env/bin/dev-env.js:7:1)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)

This is easily remediable by running require('source-map-support').install(); in the app entry point.

If we do this, we get references to the original source:

$ cdk synth

/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.ts:364
      throw new Error(`There is already a Construct with name '${childName}' in ${this.toString()}`);
            ^
Error: There is already a Construct with name 'Snapshot Complete' in [object Object]
    at ConstructNode.addChild (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.ts:364:13)
    at new ConstructNode (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.ts:62:18)
    at new Construct (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/cdk/lib/core/construct.ts:496:17)
    at new State (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/aws-stepfunctions/lib/states/state.ts:152:9)
    at new Task (/Users/otterley/src/common/snapshotter/node_modules/@aws-cdk/aws-stepfunctions/lib/states/task.ts:101:9)
    at new Snapshotter (/Users/otterley/src/common/snapshotter/lib/index.ts:72:22)
    at new DevEnvStack (/Users/otterley/src/aem/dev-env/lib/dev-env-stack.ts:19:5)
    at Object.<anonymous> (/Users/otterley/src/aem/dev-env/bin/dev-env.ts:6:1)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
otterley added a commit to otterley/aws-cdk that referenced this issue Jan 20, 2019
Install source map support so we get useful backtraces on uncaught
exceptions.

Fixes aws#1579.
otterley added a commit to otterley/aws-cdk that referenced this issue Jan 20, 2019
Add source map support to the TypeScript app entry point template.
This won't retroactively fix existing CDK apps, but it will ensure
that apps generated in the future via `cdk init --app` will have
it enabled.

Fixes aws#1579
otterley added a commit to otterley/aws-cdk that referenced this issue Jan 20, 2019
Add source map support to the TypeScript app entry point template.
This won't retroactively fix existing CDK apps, but it will ensure
that apps generated in the future via `cdk init --app` will have
it enabled.

Fixes aws#1579
@rix0rrr rix0rrr added the feature-request A feature should be added or improved. label Jan 21, 2019
@rix0rrr rix0rrr changed the title Uncaught exception backtraces point to Javascript line numbers, not TypeScript source lines Document how to enable source map support Jan 21, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 21, 2019

The following should work:

export NODE_OPTIONS="-r source-map-support"
cdk deploy

Maybe we can integrate this in a nice way somewhere, and make it as zero-conf as possible.

otterley added a commit to otterley/aws-cdk that referenced this issue Jan 21, 2019
Add source map support to the TypeScript app entry point template.
This won't retroactively fix existing CDK apps, but it will ensure
that apps generated in the future via `cdk init --app` will have
it enabled.

Fixes aws#1579
rix0rrr pushed a commit that referenced this issue Feb 4, 2019
Add source map support to the TypeScript app entry point template.
This won't retroactively fix existing CDK apps, but it will ensure
that apps generated in the future via `cdk init --app` will have
it enabled.

Fixes #1579
moofish32 pushed a commit to moofish32/aws-cdk that referenced this issue Feb 5, 2019
Add source map support to the TypeScript app entry point template.
This won't retroactively fix existing CDK apps, but it will ensure
that apps generated in the future via `cdk init --app` will have
it enabled.

Fixes aws#1579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
2 participants