components icon indicating copy to clipboard operation
components copied to clipboard

bug(schematics): migration schmatics report error without much useful information

Open princemaple opened this issue 2 years ago • 8 comments

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

Cannot read properties of undefined (reading 'sourceSpan')

Reproduction

N/A

Expected Behavior

Report file, relevant module and other useful information.

Actual Behavior

Cannot read properties of undefined (reading 'sourceSpan') and nothing else.

Environment

  • Angular: 15.0.0
  • CDK/Material: 15.0.0

princemaple avatar Nov 21 '22 04:11 princemaple

@princemaple Does the error point to a file & line number, or is this the full error message? Also, do you have an idea of which file triggered this error? If so, would you mind sharing it's contents so we can see where the parsing failed?

wagnermaciel avatar Nov 21 '22 14:11 wagnermaciel

@princemaple Does the error point to a file & line number, or is this the full error message? Also, do you have an idea of which file triggered this error? If so, would you mind sharing it's contents so we can see where the parsing failed?

That's all I got. I know which project, that's all. I don't know which file, which module. And no line number was reported. Unless there is a verbose mode that I haven't tried, I think that's all I got.

princemaple avatar Nov 21 '22 19:11 princemaple

I have a repo that has several projects in it. I think only one of them is having this issue but don't know which file. I've been migrating the other projects one by one, by limiting the migration path to projects/X.

princemaple avatar Nov 21 '22 19:11 princemaple

FYI it's not ng update. Ng update worked fine. It's the separate migration schematic.

princemaple avatar Nov 21 '22 19:11 princemaple

Hmm, I have a few guesses on what the root cause could be, but without good error logs I'll have to settle for improving the logging as an intermediary step. I'll try and land something before this Wednesday so it's included in the next patch release 👍🏽

wagnermaciel avatar Nov 21 '22 20:11 wagnermaciel

Thanks a lot 😊 I'll report back when there are more error messages shown.

princemaple avatar Nov 21 '22 20:11 princemaple

I'm seeing the same error.

I've narrowed it down to the card component by just selecting and deselecting the options in the CLI, but I cannot find the exact source file it has problems with because it seems to apply all the migrations just fine even if I do not select "card" to be migrated. I am definitely using cards in my project though.

Looking at git, the only thing it adds is some comments in style files where I override some styles and renames mat-chip-list to mat-chip-grid and mat-chip to mat-chip-row.

davidpanic avatar Nov 22 '22 10:11 davidpanic

Same for me. If I select all the components except card, then the migration will be successful. If I select card, then it gives the mysterious red message Cannot read properties of undefined (reading 'sourceSpan')

alexfung888 avatar Nov 24 '22 08:11 alexfung888

Did 15.0.1 not come out last week?

princemaple avatar Nov 30 '22 04:11 princemaple

Hello @wagnermaciel , I'm reporting back about the mdc migration.

Your undefined fix made it possible for the migration script to finish. I noticed this weird thing after migration:

image

Looks like multi line mat-card tag gave the migration script a hard time, and the previous error? Not sure if it's the real cause. Anyway, I'm very glad that I can finish this migration by just adding a space.

I'm quite surprised that this is the only place where I have a mat-card that spanned multiple lines. I'd think there were more, given how often I use mat-card :)

princemaple avatar Dec 01 '22 00:12 princemaple

Hey, that's sorta good news I guess 😅 Yeah, I think we missed a release bc of the short Thanksgiving week

I don't think multi-line mat-cards are what is causing the error, though, since we have a test for that: https://github.com/angular/components/blob/main/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.spec.ts#L99

Could you post the full <mat-card ... snippet? I can't reproduce the new issue in our tests

wagnermaciel avatar Dec 01 '22 20:12 wagnermaciel

This is what the file looked like prior to the migration.

<ng-container cdkDropListGroup>
  <mat-card
    *ngFor="let uc of userClients | async"
    [class.inactive]="!uc.user.active"
    [style.display]="!uc.user.active && !uc.clients?.length ? 'none' : 'block'"
  >
    <mat-card-title>
      {{ uc.user.name }}
    </mat-card-title>
    <mat-card-subtitle>
      {{ uc.user.sid }}
    </mat-card-subtitle>
    <mat-card-content>
      <mat-list cdkDropList (cdkDropListDropped)="assignTo(uc.user, $event)">
        <mat-list-item *ngFor="let client of uc.clients" cdkDrag [cdkDragData]="client">
          <p mat-line [title]="client.name">{{ countries[client.country].cn }} {{ client.name }}</p>
        </mat-list-item>
      </mat-list>
    </mat-card-content>
  </mat-card>
</ng-container>

princemaple avatar Dec 01 '22 21:12 princemaple

Mine.

      <mat-card
        [style.width]="na === 1 ? '90%' : '18rem'"
      >

becomes

      <mat-cardappearance="outlined"
        [style.width]="na === 1 ? '90%' : '18rem'"
      >

alexfung888 avatar Dec 01 '22 23:12 alexfung888

Latching onto this issue because it looks essentially the same.

Two differences though. The error is Cannot read properties of undefined (reading 'length') and limiting to certain components doesn't change anything.

Would love some sort of verbose option to post something more meaningful.

mralbobo avatar Jan 06 '23 14:01 mralbobo

I got the message "Cannot read properties of undefined (reading 'text')"

ThRintelen avatar Jan 13 '23 08:01 ThRintelen

I got same message as @ThRintelen . I also have "Cannot read properties of undefined (reading 'length')"

GabrielBB avatar Jan 21 '23 14:01 GabrielBB

@wagnermaciel For more info, the error is happening in this line because node is undefined :

image

GabrielBB avatar Jan 21 '23 20:01 GabrielBB

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.