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

fix(jsii): build succeeds using Omit<T, K> #1708

Merged
merged 3 commits into from
Jun 8, 2020
Merged

fix(jsii): build succeeds using Omit<T, K> #1708

merged 3 commits into from
Jun 8, 2020

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Jun 2, 2020

When using the Omit<T, K> helper type (a mapped type) on an exported
API, jsii should detect this and fail, instead of allowing the
application to compile.

An additional bug caused use of this type to result in a successful exit
code from jsii, while the .jsii file was never written. This was caused
by the mapped types symbols not having a valueDeclaration, triggering
an attempt to read undefined.parent, which threw an exception caught
by the Compiler class, but not signaled back to the caller.

Fixes #1707


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

When using the `Omit<T, K>` helper type (a mapped type) on an exported
API, `jsii` should detect this and fail, instead of allowing the
application to compile.

An additional bug caused use of this type to result in a successful exit
code from `jsii`, while the `.jsii` file was never written. This has
also been fixed.

Fixes #1707
@RomainMuller RomainMuller added bug This issue is a bug. effort/small Small work item – less than a day of effort contribution/core This is a PR that came from AWS. module/compiler Issues affecting the JSII compiler labels Jun 2, 2020
@RomainMuller RomainMuller requested a review from a team June 2, 2020 12:59
@RomainMuller RomainMuller self-assigned this Jun 2, 2020
@@ -1587,7 +1628,7 @@ export class Assembler implements Emitter {
for (const member of declaringType.getProperties()) {
if (
!(declaringType.symbol.getDeclarations() ?? []).find(
(decl) => decl === member.valueDeclaration.parent,
(decl) => decl === member.valueDeclaration?.parent,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ? here is due to valueDeclaration being nullable (despite the type declarations do not mention it).

@@ -246,6 +246,7 @@ export class Compiler implements Emitter {
diagnostics.push(...assmEmit.diagnostics);
} catch (e) {
LOG.error(`Error during type model analysis: ${e}\n${e.stack}`);
hasErrors = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This previously caused exceptions thrown from the assembler to be "swallowed" (after logging to STDERR) without necessarily causing the process to exit with non-0 (hasErrors could be false when this catch block triggers!).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 842baa8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Jun 2, 2020
for (const clause of clauses) {
for (const node of clause.types) {
const parentType = this._typeChecker.getTypeAtLocation(node);
// For some reason, we cannot trust parentType.isClassOrInterface()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand a bit with an example of when it has lost your trust?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, imported types respond false to all is* methods. :(

Comment on lines +916 to +918
`Illegal "${clauseType(clause.token)}" value for an exported API: ${
ts.SyntaxKind[badDecl.kind]
}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this error look like the neg.omit.*.ts?

Make sure it's easy to understand for an external contributor to the CDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Illegal "extends" value for an exported API: Omit<SomeInterface, 'somefield'>

I'd have wanted to make it more specific (mapped/utility types are not allowed here), however the type checker does not really give me a way to do this with confidence...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fairly good.

@RomainMuller RomainMuller removed the pr/do-not-merge This PR should not be merged at this time. label Jun 4, 2020
@mergify
Copy link
Contributor

mergify bot commented Jun 4, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Jun 4, 2020
@mergify
Copy link
Contributor

mergify bot commented Jun 4, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 9155bd0
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 4bbb3df
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit a46fdb1 into master Jun 8, 2020
@mergify mergify bot deleted the rmuller/omit branch June 8, 2020 17:21
@mergify
Copy link
Contributor

mergify bot commented Jun 8, 2020

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort module/compiler Issues affecting the JSII compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jsii build succeeds when using Omit<T, K>
3 participants