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

feat(jsii): standardized error messages #1931

Merged
merged 5 commits into from
Aug 25, 2020
Merged

Conversation

RomainMuller
Copy link
Contributor

All errors that jsii can emit now have a dedicated jsii error code (and
symbolic name), which will make it easier to track bugs related to those
as well as to provide a better experience for the documentation of the
errors, their cause, and what users should do to fix them.

This lays the foundation for being able to customize the severity of
diagnostics (non-error ones, like warnings and suggestions) individually
in order to be able to have flexibility with breaking changes.


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

All errors that jsii can emit now have a dedicated jsii error code (and
symbolic name), which will make it easier to track bugs related to those
as well as to provide a better experience for the documentation of the
errors, their cause, and what users should do to fix them.

This lays the foundation for being able to customize the severity of
diagnostics (non-error ones, like warnings and suggestions) individually
in order to be able to have flexibility with breaking changes.
@RomainMuller RomainMuller added feature-request A feature should be added or improved. effort/medium Medium work item – a couple days of effort contribution/core This is a PR that came from AWS. module/compiler Issues affecting the JSII compiler labels Aug 21, 2020
@RomainMuller RomainMuller added this to the August Release milestone Aug 21, 2020
@RomainMuller RomainMuller requested a review from a team August 21, 2020 08:11
@RomainMuller RomainMuller self-assigned this Aug 21, 2020
}

// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
readonly #defaultCategory: ts.DiagnosticCategory;
Copy link
Contributor

Choose a reason for hiding this comment

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

This # is throwing me off and I can't quickly find what it means. Do you have a reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* @param location the source code location attachment of the message.
* @param args the arguments to the message formatter.
*/
public create(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not 2 orthogonal methods?

Code.create(...).attach(...);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually want to eventually require all diagnostic messages have a source location attached, so I mean for the node to be provided upfront, always... This is why the other method is deprecated.

`Therefore, the module '${assembly.name}' must also be defined under "peerDependencies". ` +
'This will be auto-corrected unless --no-fix-peer-dependencies was specified.',
this._diagnostics.push(
JsiiDiagnostic.Code.JSII_0005_MISSING_PEER_DEPENDENCY.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

JsiiDiagnostic.Code feels rather verbose. Why not one top-level class? Ultimately we only care about the predefined JSII_0005_MISSING_PEER_DEPENDENCY (et al) constants, no? Why not make them easier to access?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're probably right. I've been self-debating this myself, too.

isThisType,
typeUse,
).addRelatedInformation(
JsiiDiagnostic.Code.JSII_9999_RELATED_INFO.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

JSII_9999_RELATED_INFO : this feels like cheating. Are "RelatedInformation"s really a type of Diagnostic?

Or do they just happen to share some features like formatting and a location and was this a convenient way to get that? Some remodeling might be in order.

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 ts.DiagnosticRelatedInformation interface is actually the base interface of ts.Diagnostic (the later only adds properties we don't care about using - reportsUnnecessary, reportsDeprecated, source - as well as the relatedInformation property that is an optional array of ts.DiagnosticRelatedInformation).

The consequence of this is that a code is needed on the related information in the exact same way that for top-level diagnostics... And those codes are actually visible to programmatic users.

@MrArnoldPalmer
Copy link
Contributor

@RomainMuller What is the convention for the error code numbers? Should we add an explanation for those to the docs?

RomainMuller added a commit that referenced this pull request Aug 24, 2020
…1903)

It is illegal in C# to name a class' member (method, property) with the
same name as the class itself (even if the member is static). Since both
class and member names are pascal-cased in C#, this means a class'
members cannot share the same PascalCased representation.

This adds a compile-time validation for this condition, effectively
calling out member names to have the same PascalCased representation
as their declaring class' name.

This is currently only a warning, as this is "made to work" by altering
the type name by appending `_` at the end of it, which is ugly and
dangerous but works, and is currently done in several places).

As all warnings, this turns into an error when operating under `--strict`,
and future work (i.e: #1931) will allow more granular configuration
of these errors, so we can hopefully opt all new codebases into the
strict behavior and eventually drop the slugification.

Fixes #1880
@RomainMuller
Copy link
Contributor Author

There isn't a general convention at this point. I've laid out some basic categories and allocated sequentially in those...

I'd like to document that the error codes are to be handled as experimental at this point and that we may re-allocate them at a later point once we have a better idea of whether there is something meaningful we should use?

@mergify
Copy link
Contributor

mergify bot commented Aug 25, 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 Aug 25, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 25, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 6aa7fa2
  • 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 b146286 into master Aug 25, 2020
@mergify mergify bot deleted the rmuller/codified-jsii-errors branch August 25, 2020 14:38
@mergify
Copy link
Contributor

mergify bot commented Aug 25, 2020

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. effort/medium Medium work item – a couple days of effort feature-request A feature should be added or improved. module/compiler Issues affecting the JSII compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants