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

A silent error is thrown in AddCommandModule.builder, when passing a version to the command ng add @my/lib@<version> #27766

Closed
1 task
Platonn opened this issue Jun 3, 2024 · 1 comment · Fixed by #27767
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix

Comments

@Platonn
Copy link
Contributor

Platonn commented Jun 3, 2024

Command

add

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Error

An exception is thrown during the method createCollection(), when the collectionName contains a @<version>, e.g. ng add @my/[email protected].

Negative consequences

The consequence is that the custom schematics' schema is not applied for parsing, i.e. the method addSchemaOptionsToCommand() is skipped, becasue of the thrown exception

And btw. the later this exception is ignored here.

Why it happens (internal Angular CLI code)

The error happens becasue eventually this line throws an error, becasue there is no such a directory like node_modules/@my/[email protected], but only node_modules/@my/lib

Because an error is thrown, a custom schema.json is not applied for parsing the arguments then.

Idea of a fix:

Before passing the collectionName as an argument to the createCollection() method, we could first extract any versions from it, e.g. by passing it through npa from 'npm-package-arg', e.g.:

private async getCollectionName(): Promise<string> {
    const [, collection] = this.context.args.positional;

    const packageIdentifier = npa(collection);
    return packageIdentifier.name;
  }

Additional notes

  • ng add @my/[email protected] - causes error
  • ng add @my/lib@ (with just @) - also causes error
  • ng add @my/lib (nothing after the package's name) - doesn't cause error

Minimal Reproduction

  1. Create a fresh angular 17 app

  2. In VSCode add a console.error({error}) in the AngularCLI's file node_modules/@angular/cli/src/commands/add/cli.js in line 80 (inside this catch block):

    } catch (error) {
    // During `ng add` prior to the downloading of the package
    // we are not able to resolve and create a collection.
    // Or when the collection value is a path to a tarball.
    }

    see example:
    image

  3. (run npm install @my/lib - to mitigate the bug Schematic with multi select x-promt errors when using command line parameter: 'path ".foo" should be array' #16320 - but ideally this step shouldn't be needed when this other bug is fixed)

  4. run ng add @my/library@<with-version-here>

  5. See an error in the console error: CollectionCannotBeResolvedException [Error]: Collection "@my/[email protected]" cannot be resolved.

Your Environment

Angular CLI: 17.3.8
Node: 20.11.0
Package Manager: npm 10.2.4
OS: darwin arm64

Angular: 17.3.10
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
... service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.8
@angular-devkit/build-angular   17.3.8
@angular-devkit/core            17.3.8
@angular-devkit/schematics      17.3.8
@angular/cli                    17.3.8
@schematics/angular             17.3.8
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.6

Anything else relevant?

No response

@Platonn Platonn changed the title A silent error is thrown in AddCommandModule.builder, when passing a version to the command ng add @my-lib@<version> A silent error is thrown in AddCommandModule.builder, when passing a version to the command ng add @my/lib@<version> Jun 3, 2024
Platonn added a commit to Platonn/angular-cli that referenced this issue Jun 3, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
Platonn added a commit to Platonn/angular-cli that referenced this issue Jun 3, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
Platonn added a commit to Platonn/angular-cli that referenced this issue Jun 3, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken area: @angular/cli labels Jun 3, 2024
Platonn added a commit to Platonn/angular-cli that referenced this issue Jun 3, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
Platonn added a commit to Platonn/angular-cli that referenced this issue Jun 4, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
dgp1130 pushed a commit that referenced this issue Jun 4, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes #27766
dgp1130 pushed a commit that referenced this issue Jun 4, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes #27766

(cherry picked from commit ce8b5a3)
celestius0 pushed a commit to celestius0/angular-cli that referenced this issue Jun 5, 2024
…when a version is passed to `ng add <package>@<version>`

This commit fixes the method `AddCommandModule.getCollectionName()`, so it now returns only the package name, but remove the specified version (if present).

Previously, a `@<version>` specified in the const `collectionName` was causing a (silenced) error during the invocation of `workflow.engine.createCollection(collectionName)`, which lead to skipping eventually the invocation of the method `this.addSchemaOptionsToCommand()` in the try/catch block.

fixes angular#27766
@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 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
2 participants