question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing null options to RunSchematicTask leads to CLI crash

See original GitHub issue

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 11.x

Description

Using context.addTask(new RunSchematicTask(schematicName, Options)) inside a schematic, we can schedule another schematic. Until (including) Angular 11 we could simply pass null as second Options parameter. Starting with Angular 12 the CLI will crash with the error message Cannot read property 'project' of null.

🔬 Minimal Reproduction

Run a schematic (using ng add or ng g) that itself tries to run another schematic using context.addTask(new RunSchematicTask(schematicName, null)) (null is important here).

Since the ng-add schematic of @da-mkay/ng-builder-electron uses the above mentioned code you can use these commands to reproduce the issue:

$ ng new workspace --create-application=false
$ cd workspace
$ ng add @da-mkay/ng-builder-electron@0.2.0

(Version 0.2.0 is important as I will release a new version in a moment)

🔥 Exception or Error


Cannot read property 'project' of null

🌍 Your Environment


Angular CLI: 12.0.2
Node: 14.17.0
Package Manager: npm 6.14.13
OS: darwin x64

Angular: 12.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1200.2
@angular-devkit/core         12.0.2
@angular-devkit/schematics   12.0.2
@schematics/angular          12.0.2
rxjs                         6.6.7
typescript                   4.2.4

Anything else relevant?

The issue is caused by the following line inside SchematicCommand class: https://github.com/angular/angular-cli/blob/master/packages/angular/cli/models/schematic-command.ts#L247

typeof (current as Record<string, unknown>).project === 'string'

Here, current is what we pass as second argument to the RunSchematicTask constructor (null). Since that parameter is typed as generic T, IMHO we should be able to pass null here. But maybe I’m wrong 😉

As a workaround I can pass {} instead of null to the RunSchematicTask constructor.

A solution would be to change the above line to:

typeof (current as Record<string, unknown>)?.project === 'string'

(added ?)

I can also create a PR for that gigantic change if needed 😋

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, Jun 6, 2021

@martinakraus, go for it!

0reactions
angular-automatic-lock-bot[bot]commented, May 19, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different ways to run schematics from another ... - InDepth.Dev
For our use-case, we will use RunSchematicTask . It has 2 constructor overrides: constructor(schemaName: string, options: T) - Runs schematic ...
Read more >
Application is crashing with null pointer exception if i pass null ...
When i pass null value to the method it is crashing, i don't know why my logic is wrong or what. Please help...
Read more >
Laravel:Call To A Member Function Store() On Null - ADocLib
Passing null options to RunSchematicTask leads to CLI crash Needs to be more explicit by calling the function in the example. Next Fatal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found