angular / angular/angular-cli

Schematics template syntax errors should point to the offending template

オープン
#13,192 コメント 0 件 リアクション 14 件 担当者 0 名 GitHub で見る
area: @angular-devkit/schematics freq1: low severity3: broken type: bug/fix
主要言語
TypeScript
スター
27k
フォーク
11.8k
平均マージ
14時間 23分
マージ済み PR(30日)
162

説明

### Bug Report or Feature Request (mark with an `x`)
```
- [ ] bug report -> please search issues before submitting
- [x] feature request
```

### Repro steps

- Have a syntax error in your template.
- Run the schematic with `--debug`, and get a stack trace that points to schematics code, but that doesn't point to any of your own code.

### The log given by the failure
This is easier to handle when you when the syntax error is something simple like misspelling a variable name, e.g. you pass in template variable `foobar` and have a template with `<%= foobat %>`:
```
An error occured:
ReferenceError: foobat is not defined
at eval (eval at template (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/node_modules/@angular-devkit/core/src/utils/template.js:257:16), :22:18)
at /usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/template.js:35:79
at tree.visit (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/base.js:130:30)
at files.forEach.path (/usr/local/google/home/nsidhom/.nvm/versions/node/v10.1.0/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/tree/virtual.js:131:40)
at Array.forEach ()
at FileSystemCreateTree.visit (/usr/local/google/home/nsidhom/.nvm/versions/node/v10.1.0/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/tree/virtual.js:131:24)
at /usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/base.js:126:14
at MergeMapSubscriber.input.pipe.operators_1.mergeMap.inputTree [as project] (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/call.js:77:24)
at MergeMapSubscriber._tryNext (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:65:27)
at MergeMapSubscriber._next (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:55:18)
```

But if you have a syntax error such as putting an unintended second symbol within the brackets like `<%= foobar unintended %>`, then you just get `SyntaxError: Unexpected identifier`, which could be anywhere and is hard to hunt down:
```
An error occured:
SyntaxError: Unexpected identifier
at Function ()
at Object.template (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/node_modules/@angular-devkit/core/src/utils/template.js:257:16)
at /usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/template.js:35:40
at tree.visit (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/base.js:130:30)
at files.forEach.path (/usr/local/google/home/nsidhom/.nvm/versions/node/v10.1.0/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/tree/virtual.js:131:40)
at Array.forEach ()
at FileSystemCreateTree.visit (/usr/local/google/home/nsidhom/.nvm/versions/node/v10.1.0/lib/node_modules/@angular-devkit/schematics-cli/node_modules/@angular-devkit/schematics/src/tree/virtual.js:131:24)
at /usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/base.js:126:14
at MergeMapSubscriber.input.pipe.operators_1.mergeMap.inputTree [as project] (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/src/rules/call.js:77:24)
at MergeMapSubscriber._tryNext (/usr/local/google/home/nsidhom/schematics/pantheon/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:65:27)
```

### Desired functionality
I would like for the error to point me to the offending template, and if possible, the offending line of the template. As is, these errors are incredibly hard to debug.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

schematics を --debug で実行して不正な template 式を再現し、その後、stack trace に示された template.js の箇所、特に @angular-devkit/core/src/utils/template.js と @angular-devkit/schematics/src/rules/template.js から調査を始めます。構文エラーが問題の template と、可能であればその行を特定し、単に一般的な parser の位置だけを報告しない状態になれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
cli, tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。