angular / angular/angular-cli

Schematics : Copy then delete can cause "This should never happen" error.

Offen
#16,527 0 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: @angular-devkit/schematics freq1: low severity3: broken type: bug/fix
Vorherrschende Sprache
TypeScript
Sterne
27k
Forks
11.8k
Ø Merge
14 Std. 23 Min.
Gemergte PRs (30 T.)
162

Beschreibung

# 🐞 Bug report

### Description

Moving files as part of a schematic can cause an error to be thrown:

```bash
Message:
Error: This should never happen. Path: "/projects/bar".
```

It seems to happen if those files were created by a previous rule and the move is done by copy and deletion.

(As an aside here, it _seems_ that delete operations are hoisted somehow...whenever they occur in a schematic, the logger output shows them to always happen first, this is *not* what I'd expect)

I'm aware that there is a `move` rule in `@angular-devkit/schematics/src/rules`, but this **does not work**. Attempting to use this rule to move files from one folder to another results in this error: `ENOENT: no such file or directory, rename '' -> ''`

## 🔬 Minimal Reproduction

```ts
export function move(schema: Schema): Rule {
return (host: Tree, _context: SchematicContext): Tree => {
const dir = host.getDir(schema.source);
dir.visit(file => {
const newPath = file.replace(schema.source, schema.destination);

const buffer = host.read(file);
if (buffer === null) {
return;
}

host.create(newPath, buffer);
});

host.delete(schema.source);

return host;
};
}
```

See also: https://github.com/jdpearce/move-schematic

NB - this schematic will probably work if run against a pre-existing workspace, but when the tree is set up by another schematic, as in the spec file, that's when the error is thrown.

## 🌍 Your Environment

Angular CLI: 8.3.21
Node: 13.5.0
OS: darwin x64
Angular: undefined
...

Package Version
------------------------------------------------------
@angular-devkit/architect 0.803.21 (cli-only)
@angular-devkit/core 8.3.21
@angular-devkit/schematics 8.3.21
@schematics/angular 8.3.21
@schematics/update 0.803.21 (cli-only)
rxjs 6.5.4
typescript 3.5.3

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Führe zunächst die minimale Reproduktion aus der schematischen Spezifikation des Issues aus, insbesondere wenn der Tree von einem anderen Schematic erstellt wird. Untersuche dann das Copy/Delete-Verhalten von Tree und die Move-Regel in @angular-devkit/schematics/src/rules. Erledigt ist die Aufgabe, wenn der Copy-then-delete-Fall nicht mehr „This should never happen“ auslöst und die Move-Regel ENOENT nicht mehr meldet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.