-
Notifications
You must be signed in to change notification settings - Fork 399
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(compiler): Implement error codes system onto compiler modules #726
Conversation
@@ -0,0 +1,2 @@ | |||
src/ | |||
.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lwc-errors module starts here
@@ -0,0 +1,90 @@ | |||
import { LWCErrorInfo, templateString } from "../shared/utils"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main error utilities live here.
@@ -0,0 +1,76 @@ | |||
const errors = require('../dist/commonjs/index.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This babel transform was written for the engine modules, so it will be removed.
@@ -0,0 +1,215 @@ | |||
import { Level } from "../../shared/utils"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error code metadata starts here. Looking at the whole picture might help us decide how to organize the numeric codes.
INVALID_STATIC_OBSERVEDATTRIBUTES: { | ||
code: 0, | ||
message: "Invalid static property \"observedAttributes\". \"observedAttributes\" cannot be used to track attribute changes. Define setters for {0} instead.", | ||
type: "path.buildCodeFrameError", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type was originally meant to help us surface typed errors, but doesn't seem to have any purpose if we're normalizing to CompilerError. If there are no concerns, I'll remove this property.
return new CompilerError(errorInfo.code, fullMessage, filename, location); | ||
} | ||
|
||
export function normalizeCompilerError(error: any, newContext?: CompilerContext): CompilerError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalizeToCompilerError?
@@ -212,7 +212,7 @@ describe('Transform property', () => { | |||
} | |||
`, { | |||
error: { | |||
message: 'test.js: Boolean public property must default to false.', | |||
message: 'Boolean public property must default to false.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests made to be more tolerant to changes to the overall error message.
this is a very very long PR, is there a doc somewhere to understand this better? |
It's changed a little since then but we had a few discussions around the following docs and the linked resources: Initial summary - https://salesforce.quip.com/3aSCA6NzEHcE |
@caridy understands now how we feel with hist refactors :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are few things that i would like to revisit:
- Centralized vs Distributed Error Messages: should each package within the repo contain its own errors file instead of lwc-error owning all the errors? I feel like naming convention could be simplified if each package holds all its messages.
- Naming convention scheme: If we do keep all the errors inside the lwc-errors, should each folder representing a sub-package match the name of the module it holds the errors for? ex: lwc-compiler errors will be represented as lwc-errors/src/lwc-compiler/errors.ts
- Error type: should error type represent a package or an operation? If an invariant error is thrown from the compiler, is it sufficient to say that it was a 'transform' type? Or do we want to flag the origin, such as 'compiler'?
- package structure: since everything is technically related to errors, do we need an extra error-info folder or will src//errors.ts be sufficient? ( current: lwc-errors/src/compiler/error-info/babel-plugin-lwc-class.ts)
- should the generateCompilerError accept a message and a config object instead of explicitly listing all the params ( see comment below )?
@@ -293,7 +293,7 @@ describe('Transform property', () => { | |||
} | |||
`, { | |||
error: { | |||
message: 'test.js: Ambiguous attribute name tabindex. tabindex will never be called from template because its corresponding property is camel cased. Consider renaming to "tabIndex".', | |||
message: 'Ambiguous attribute name tabindex. tabindex will never be called from template because its corresponding property is camel cased. Consider renaming to "tabIndex".', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls wrap property name in quote? "tabindex"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above:
Ambiguous attribute name "tabindex". "tabindex" will never be called from template because its corresponding property is camel cased. Consider renaming to "tabIndex".'
@@ -308,7 +308,7 @@ describe('Transform property', () => { | |||
} | |||
`, { | |||
error: { | |||
message: 'test.js: Ambiguous attribute name maxlength. maxlength will never be called from template because its corresponding property is camel cased. Consider renaming to "maxLength".', | |||
message: 'Ambiguous attribute name maxlength. maxlength will never be called from template because its corresponding property is camel cased. Consider renaming to "maxLength".', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
throw new TypeError(`Expected an object with files to be compiled.`); | ||
} | ||
invariant( | ||
!isUndefined(options.files) && !!Object.keys(options.files).length, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe we can just do
Object.keys(options.files).length
as it is a truthy value;
not unless you explicitly expect a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning !! not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invariant function does expect a boolean though. Is this worth changing the type to any
?
@@ -25,7 +25,7 @@ export default function compiler( | |||
|
|||
let code = ''; | |||
const warnings: CompilationWarning[] = []; | |||
|
|||
// TODO ERROR CODES: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Some thoughts on your thoughts; we can discuss more tomorrow too:
With a centralized package, it's easier to validate that each error code is unique when we compile the package and we can eventually have all the error-related documentation in one place. The other benefit was being able to organize the errors independently from how the packages are organized. Looking at the whole thing though, the errors are mostly fairly specific to their packages, so we might not want to organize them independently anymore. If we're organizing by package anyways, I don't see why each package can't just contain its own errors file. The main concern would be verifying the error codes. Also, would the errors docs live with each package too?
Yeah that's one way we can organize things if we want to go with a deeper file structure. I personally feel that this would be better than the flat directory (/src/everything-here) if we decide to organize by source package.
The error instance itself should inherently provide the origin since it is a 'CompilerError'. For type, do we still need that property? Looking at the big picture, since we're normalizing to 'CompilerError', I'm not sure it's useful anymore. If we want to surface the error's origin sub-package, maybe that would be better served by a utility that lets each sub-package prepend some message to the error. Thoughts on that?
I mainly did that so it's easier to distinguish the files purely holding the error metadata from the error-related code/utilities. If that's not helpful we can definitely flatten it again, but I think I prefer the deeper directory structure.
Yes, that's much better |
who can do a walk thru this PR in a quick chat this week? |
We should do it tomorrow
…On Wed, Oct 17, 2018 at 9:43 AM Caridy Patiño ***@***.***> wrote:
who can do a walk thru this PR in a quick chat this week?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#726 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABH0qLMAxrmgxzAWxiiexzB8X29U_fLsks5ul14bgaJpZM4XWcFD>
.
|
016fd49
to
f7eabb4
Compare
Whenever @caridy can, hopefully today? Otherwise I will do another final pass and merge it EOW |
Sounds good. There are a few more changes that should be ready tonight, so no rush on that final pass. |
Just realized a few hours ago that the remaining changes to expose the new error shape through lwc-compiler are going to break downstream modules expecting the old error shape (aura, platform-compiler). Going to add a temporary converter to maintain the existing API so that we don't need to do any coordinated releases on a huge PR like this. Thoughts? Also, are aura and platform-compiler the only places that use lwc-compiler, or are there more? |
@jye-sf don't quite follow that lets talk once you are in the office, or hangouts |
The diagnostics are part of the lwc-compiler API, so we hit compilation errors in platform-compiler, and anything relying on the old 'location' info will break.
|
startCol: number; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our parse5 version is older, while jsdom is using a newer version. This the right way to resolve it?
export interface CssSyntaxError { | ||
lwcCode?: number; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add property to library Error object so we can pass the error code.
@@ -0,0 +1,3 @@ | |||
declare interface Error { | |||
lwcCode?: number | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add property to library Error object so we can pass the error code.
0148960
to
828e9b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Jason and I have discussed all of the outstanding comments offline and concluded that we are going to hold off on some of them until the next pass. @jye-sf please create a git issue to track the future changes that we need to revisit.
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
Creates the 'lwc-errors' module for error handling and normalization
Implements the error codes system onto lwc compiler modules. These include:
Does this PR introduce a breaking change?
If yes, please describe the impact and migration path for existing applications: