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(cdk/schematics): errors when attempting to read some files #19783

Merged

Conversation

crisbeto
Copy link
Member

In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have strictNullChecks enabled which prevented the compiler from reporting the errors.

Fixes #19779.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround merge safe target: patch This PR is targeted for the next patch release labels Jun 27, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 27, 2020
In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have `strictNullChecks` enabled which prevented the compiler from reporting the errors.

Fixes angular#19779.
@crisbeto crisbeto force-pushed the 19779/cdk-schematics-null-pointer-errors branch from 5dfa833 to 8b98f30 Compare June 27, 2020 05:59
// In case the stylesheet does not exist in the file system, skip it gracefully.
if (!this._fileSystem.exists(stylesheetPath)) {
return;
if (stylesheet) {
Copy link
Member

Choose a reason for hiding this comment

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

The change in general is good (enabling strict), but I wonder how this issue surfaces? Do we understand how this can happen? We asserted that a file exists in the virtual tree, and then read from it? Reading the file from the tree should not be null, or is this an edge case when a file is not readable somehow?

https://cs.opensource.google/angular/angular-cli/+/master:packages/angular_devkit/schematics/src/tree/host-tree.ts;l=282-291?q=read&ss=angular%2Fangular-cli

Copy link
Member Author

Choose a reason for hiding this comment

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

The assertion here was fine, but I think it failed on the one below where we didn't have an assertion.

Copy link
Member

@devversion devversion Jun 29, 2020

Choose a reason for hiding this comment

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

Unless I miss something, we had a check before we invoked resolveExternalStylesheet. And the other one just accepted a glob of source files which are guaranteed to exist in FS.

Maybe the glob returned source files which exist on FS but are not available in the virtual file system. That would seem most likely. It would be good understanding this as it could potentially be a bug in the devkit, or general reasoning required for future schematic work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess it depends on whether the resolve call here corresponds to a path.resolve from Node which won't check the file system, or whether it's something different that actually does the lookup. If it's the latter, your explanation sounds plausible. Either way, I think that we should get this in for the next release so people that are updating to v10 don't run into it.

Copy link
Member

Choose a reason for hiding this comment

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

The resolve call should not be relevant here. The list of additionalStylesheetPaths is based on a real file system query, and resolve just turns the absolute FS path into a virtual FS workspace relative path.

So there are two options: Either the files are somehow not readable and are not added to the virtual FS tree, or our path resolution logic is flawed. And this is the point/issue I think we should figure out. Fixing the issue is great, but understanding the root cause seems beneficial. To be clear: From the beginning on I agreed that this is a good change to land either way, but it would be still worth figuring this out I assume. I'll ask the issue reporter for more information.

Also I think since this has been reported only once and seems very edgy/surprising, this is probably not P2 worthy.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added lgtm action: merge The PR is ready for merge by the caretaker labels Jun 29, 2020
@devversion devversion added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed P2 The issue is important to a large percentage of users, with a workaround labels Jun 29, 2020
@jelbourn jelbourn merged commit 00c5a53 into angular:master Jun 30, 2020
jelbourn pushed a commit that referenced this pull request Jun 30, 2020
In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have `strictNullChecks` enabled which prevented the compiler from reporting the errors.

Fixes #19779.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(cdk): Update Failed : Cannot read property 'length' of null
4 participants