Fix: Cannot read property 'pass-thru' of undefined crash (#3984)

* Fix for #3908

Validate that value is available before reading configuration.

Offending plugin in my case with `imodeler1`

* Add changes

* Fix build error

* Apply suggestions from code review

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>

* Update pipeline.ts

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
This commit is contained in:
Andrii Kurdiumov 2021-03-16 21:49:02 +06:00 коммит произвёл GitHub
Родитель 5a47e7dbc2
Коммит 25cbf0fc97
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 14 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@autorest/core",
"comment": "**Fix** Cannot read property 'pass-thru' of undefined crash",
"type": "patch"
}
],
"packageName": "@autorest/core",
"email": "kant2002@gmail.com"
}

Просмотреть файл

@ -359,12 +359,12 @@ export async function runPipeline(configView: AutorestContext, fileSystem: IFile
// you can have --pass-thru:FOO on the command line // you can have --pass-thru:FOO on the command line
// or add pass-thru: true in a pipline configuration step. // or add pass-thru: true in a pipline configuration step.
const configEntry = context.GetEntry(node.configScope.last.toString());
const passthru = const passthru =
context.GetEntry(node.configScope.last.toString())["pass-thru"] === true || configEntry?.["pass-thru"] === true ||
values(configView.GetEntry("pass-thru")).any((each) => each === pluginName); values(configView.GetEntry("pass-thru")).any((each) => each === pluginName);
const usenull = const usenull =
context.GetEntry(node.configScope.last.toString())["null"] === true || configEntry?.["null"] === true || values(configView.GetEntry("null")).any((each) => each === pluginName);
values(configView.GetEntry("null")).any((each) => each === pluginName);
const plugin = usenull ? plugins.null : passthru ? plugins.identity : plugins[pluginName]; const plugin = usenull ? plugins.null : passthru ? plugins.identity : plugins[pluginName];