aws / aws/jsii

Better `jsii-pacmak` error when dependencies doesn't have an expected target platform

Open
#3,403 0 comments 1 reaction 0 assignees View on GitHub
bug language/dotnet module/pacmak needs-reproduction p1
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

## :bug: Bug Report

### Affected Languages

- [ ] `TypeScript` or `Javascript`
- [ ] `Python`
- [ ] `Java`
- [x] .NET (`C#`, `F#`, ...)
- [ ] `Go`

### General Information
* **JSII Version:** 1.54.0 (build b1b977a)`
* **Platform:** 5.10.60.1-microsoft-standard-WSL2

Realted to https://github.com/awslabs/cdk-serverless-clamscan/issues/355
When attempting to create a `.NET` package of my project with the following in the `.jsii` using `npx jsii-pacmak -v --target dotnet`

```json
"repository": {
"type": "git",
"url": "https://github.com/awslabs/cdk-serverless-clamscan"
},
"schema": "jsii/0.10.0",
"targets": {
"dotnet": {
"namespace": "cdk.serverless.clamscan",
"packageId": "cdk.serverless.clamscan"
},
"js": {
"npm": "cdk-serverless-clamscan"
},
"python": {
"distName": "cdk-serverless-clamscan",
"module": "cdk_serverless_clamscan"
}
},
```

I received the error in the `Cannot read property 'namespace' of undefined`. After some debugging I *think* the error is caused by one of the `dependencies` not having a `dotnet` target.

```json
"cdk-nag": {
...
"targets": {
"js": {
"npm": "cdk-nag"
},
"python": {
"distName": "cdk-nag",
"module": "cdk_nag"
}
}
},
```

If this is the case there should be better error messages and property checking for targets on dependencies.

### Verbose Log
``` bash
$ npx jsii-pacmak -v --target dotnet
[jsii-pacmak] [INFO] Found 1 modules to package
[jsii-pacmak] [INFO] Packaging NPM bundles
[jsii-pacmak] [INFO] Loading jsii assemblies and translations
[jsii-pacmak] [INFO] Packaging 'dotnet' for cdk-serverless-clamscan
[jsii-pacmak] [WARN] Exception occurred, not cleaning up
[jsii-pacmak] [WARN] dotnet failed
TypeError: Cannot read property 'namespace' of undefined
at DotNetTypeResolver.resolveNamespacesDependencies (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/targets/dotnet/dotnettyperesolver.js:71:46)
at DotNetGenerator.generate (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.js:43:27)
at Dotnet.generateCode (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/target.js:29:28)
at async DotnetBuilder.generateModuleCode (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/targets/dotnet.js:94:9)
at async /home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/targets/dotnet.js:62:30
at async Function.make (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/util.js:227:36)
at async DotnetBuilder.buildModules (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/targets/dotnet.js:35:35)
at async Promise.all (index 0)
at async Object.pacmak (/home/dontirun/.npm/_npx/4ad69527ec0d2015/node_modules/jsii-pacmak/lib/index.js:61:9)
```

Contributor guide

Open the contributing guide

Research direction

Start with jsii-pacmak/lib/targets/dotnet/dotnettyperesolver.js at the reported failure and trace the call from dotnetgenerator.js. Reproduce the command with the shown dependency setup, then make the missing dependency target produce a clear error instead of the namespace TypeError; verify the behavior with the relevant existing tests, if present.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.