fix(@angular-devkit/architect): improve error message when configuration is missing

This commit makes the error message more actionable.

Closes #29742
This commit is contained in:
Alan Agius 2025-03-04 08:57:05 +00:00
parent 280693231e
commit 6f0e90e215
2 changed files with 10 additions and 14 deletions

View File

@ -90,7 +90,9 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
}
if (!targetDefinition.configurations?.[configuration]) {
throw new Error(`Configuration '${configuration}' is not set in the workspace.`);
throw new Error(
`Configuration '${configuration}' for target '${target}' in project '${project}' is not set in the workspace.`,
);
}
return (targetDefinition.configurations?.[configuration] ?? {}) as json.JsonObject;

View File

@ -1,17 +1,11 @@
import assert from 'node:assert';
import { ng } from '../../utils/process';
import { expectToFail } from '../../utils/utils';
export default async function () {
try {
await ng('build', '--configuration', 'invalid');
throw new Error('should have failed.');
} catch (error) {
if (
!(
error instanceof Error &&
error.message.includes(`Configuration 'invalid' is not set in the workspace`)
)
) {
throw error;
}
}
const error = await expectToFail(() => ng('build', '--configuration', 'invalid'));
assert.match(
error.message,
/Configuration 'invalid' for target 'build' in project 'test-project' is not set in the workspace/,
);
}