Skip to content

Commit 7f7a087

Browse files
committed
fixup! fix(@angular-devkit/schematics): include the template path in errors thrown by content templates
1 parent 4bb42d8 commit 7f7a087

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎packages/angular_devkit/schematics/src/rules/template.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export function applyContentTemplate<T>(options: T): FileOperator {
7777
content: Buffer.from(templateImpl(decodedContent, {})(options)),
7878
};
7979
} catch (e) {
80-
throw new Error(`Failed to apply template "${path}": ${String(e)}`, { cause: e });
80+
const message = e instanceof Error ? e.message : String(e);
81+
82+
throw new Error(`Failed to apply content template to "${path}": ${message}`, { cause: e });
8183
}
8284
};
8385
}

‎packages/angular_devkit/schematics/src/rules/template_spec.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* eslint-disable import/no-extraneous-dependencies */
1010
import { normalize } from '@angular-devkit/core';
11-
import { of as observableOf } from 'rxjs';
11+
import { lastValueFrom, of as observableOf } from 'rxjs';
1212
import { UnitTestTree } from '../../testing';
1313
import { SchematicContext } from '../engine/interface';
1414
import { HostTree } from '../tree/host-tree';
@@ -188,10 +188,10 @@ describe('contentTemplate', () => {
188188
const operator = applyContentTemplate({ foobar: 1 });
189189

190190
expect(() => operator(_entry('/a/b/file.ts', 'a<%= foobat %>b'))).toThrowError(
191-
'Failed to apply template "/a/b/file.ts": ReferenceError: foobat is not defined',
191+
'Failed to apply content template to "/a/b/file.ts": foobat is not defined',
192192
);
193193
expect(() => operator(_entry('/a/b/file.ts', 'a<%= foobar unintended %>b'))).toThrowError(
194-
/^Failed to apply template "\/a\/b\/file\.ts": SyntaxError: /,
194+
/^Failed to apply content template to "\/a\/b\/file\.ts": Unexpected identifier/,
195195
);
196196
});
197197

@@ -239,7 +239,9 @@ describe('applyTemplateFiles', () => {
239239
} as SchematicContext;
240240

241241
await expectAsync(
242-
callRule(applyTemplates({ a: 'foo' }), observableOf(tree), context).toPromise(),
243-
).toBeRejectedWithError(/^Failed to apply template "\/a\/b\/file__a__\.template": TypeError: /);
242+
lastValueFrom(callRule(applyTemplates({ a: 'foo' }), observableOf(tree), context)),
243+
).toBeRejectedWithError(
244+
/^Failed to apply content template to "\/a\/b\/file__a__\.template": Cannot read /,
245+
);
244246
});
245247
});

0 commit comments

Comments
 (0)