Skip to content

fix(ngcc): do not fail hard when a format-path points to a non-existing or empty file#40985

Closed
gkalpak wants to merge 2 commits intoangular:masterfrom
gkalpak:fix-ngcc-missing-format-path
Closed

fix(ngcc): do not fail hard when a format-path points to a non-existing or empty file#40985
gkalpak wants to merge 2 commits intoangular:masterfrom
gkalpak:fix-ngcc-missing-format-path

Conversation

@gkalpak
Copy link
Copy Markdown
Member

@gkalpak gkalpak commented Feb 24, 2021

Previously, when ngcc encountered an entry-point with a format-path that pointed to a non-existing or empty file it would throw an error and stop processing the remaining tasks.

In the past, we used to ignore such format-paths and continue processing the rest of the tasks (see code). This was changed to a hard failure in 2954d1b. Looking at the code history, the reason for changing the behavior was an (incorrect) assumption that the condition could not fail. This assumption failed to take into account the case where a 3rd-party library has an invalid format-path in its package.json. This is an issue with the library, but it should not prevent ngcc from processing other packages/entry-points/formats.

This commit fixes this by reporting the task as failed but not throwing an error, thus allowing ngcc to continue processing other tasks.

Fixes #40965.

@mary-poppins
Copy link
Copy Markdown

@gkalpak gkalpak force-pushed the fix-ngcc-missing-format-path branch from 0b49aee to e8a341a Compare February 24, 2021 20:42
@mary-poppins
Copy link
Copy Markdown

…ng or empty file

Previously, when `ngcc` encountered an entry-point with a format-path
that pointed to a non-existing or empty file it would throw an error and
stop processing the remaining tasks.

In the past, we used to ignore such format-paths and continue processing
the rest of the tasks ([see code][1]). This was changed to a hard
failure in 2954d1b. Looking at the code
history, the reason for changing the behavior was an (incorrect)
assumption that the condition could not fail. This assumption failed to
take into account the case where a 3rd-party library has an invalid
format-path in its `package.json`. This is an issue with the library,
but it should not prevent `ngcc` from processing other
packages/entry-points/formats.

This commit fixes this by reporting the task as failed but not throwing
an error, thus allowing `ngcc` to continue processing other tasks.

[1]: https://github.com/angular/angular/blob/3077c9a1f89c5bd75fb96c16e/packages/compiler-cli/ngcc/src/main.ts#L124

Fixes angular#40965
@gkalpak gkalpak force-pushed the fix-ngcc-missing-format-path branch from e8a341a to d0a6348 Compare February 25, 2021 09:37
@mary-poppins
Copy link
Copy Markdown

@gkalpak gkalpak marked this pull request as ready for review February 25, 2021 10:01
@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed state: WIP labels Feb 25, 2021
`${formatProperty} (formatPath: ${formatPath} | format: ${format})`);
onTaskCompleted(
task, TaskProcessingOutcome.Failed,
`property '${formatProperty}' pointing to a missing or empty file (${formatPath}).`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Subjective NIT:

Suggested change
`property '${formatProperty}' pointing to a missing or empty file (${formatPath}).`);
`property \`${formatProperty}\` pointing to a missing or empty file: ${formatPath}.`);

function createErrorMessage(fs: ReadonlyFileSystem, task: Task, message: string|null): string {
const jsFormat =
`${task.formatProperty} as ${getEntryPointFormat(fs, task.entryPoint, task.formatProperty)}`;
const jsFormat = `${task.formatProperty} as ${
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Subjective NIT:

Suggested change
const jsFormat = `${task.formatProperty} as ${
const jsFormat = `\`${task.formatProperty}\` as ${

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seems out of scope for this PR.
(Also, you do realize this is your code, right? 😛)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that you are changing the line anyway. (And I have never been one to ideologically stick with my previous decisions).

const logger = new MockLogger();
mainNgcc({
basePath: '/dist',
propertiesToConsider: ['es2015', 'fesm5', 'main'],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps put the main property earlier in the list so that we can see that it failure does not block other formats from being processed.

Also, what happens if the main property is the one that is assigned to the typings processing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also, what happens if the main property is the one that is assigned to the typings processing?

Not great things 😁

Hopefully, since main is low in the list of default properties to consider (and in CLI's list of properties), main will rarely be associated with processing typings.

In any case, this is not much different from what would happen if the formatPath for another property (which is associated with typings processing) points to a missing/empty file. In fact, ngcc seems to fail silently (from a super-quick loog) in that case, which is argueably worse than failing the taks and printing an error message 😁

@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Feb 25, 2021
@gkalpak gkalpak force-pushed the fix-ngcc-missing-format-path branch from 55a33b7 to fcb6051 Compare February 25, 2021 15:03
@mary-poppins
Copy link
Copy Markdown

@gkalpak gkalpak force-pushed the fix-ngcc-missing-format-path branch from fcb6051 to f82d92b Compare February 25, 2021 15:20
@mary-poppins
Copy link
Copy Markdown

@gkalpak gkalpak force-pushed the fix-ngcc-missing-format-path branch from f82d92b to 50265ed Compare February 25, 2021 15:44
@mary-poppins
Copy link
Copy Markdown

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Feb 25, 2021
@ngbot

This comment has been minimized.

@zarend zarend closed this in 284af73 Feb 26, 2021
zarend pushed a commit that referenced this pull request Feb 26, 2021
…ng or empty file (#40985)

Previously, when `ngcc` encountered an entry-point with a format-path
that pointed to a non-existing or empty file it would throw an error and
stop processing the remaining tasks.

In the past, we used to ignore such format-paths and continue processing
the rest of the tasks ([see code][1]). This was changed to a hard
failure in 2954d1b. Looking at the code
history, the reason for changing the behavior was an (incorrect)
assumption that the condition could not fail. This assumption failed to
take into account the case where a 3rd-party library has an invalid
format-path in its `package.json`. This is an issue with the library,
but it should not prevent `ngcc` from processing other
packages/entry-points/formats.

This commit fixes this by reporting the task as failed but not throwing
an error, thus allowing `ngcc` to continue processing other tasks.

[1]: https://github.com/angular/angular/blob/3077c9a1f89c5bd75fb96c16e/packages/compiler-cli/ngcc/src/main.ts#L124

Fixes #40965

PR Close #40985
@gkalpak gkalpak deleted the fix-ngcc-missing-format-path branch February 26, 2021 17:02
@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Mar 29, 2021
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 target: patch This PR is targeted for the next patch release type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ngcc fails and produces a confusing error when a library points to a non-existent file

4 participants