Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# compiled output
dist
tmp
/out-tsc
out-tsc/

# dependencies
node_modules
Expand Down Expand Up @@ -51,4 +51,4 @@ vitest.config.*.timestamp*
.github/instructions/nx.instructions.md

.claude/worktrees
.claude/settings.local.json
.claude/settings.local.json
61 changes: 27 additions & 34 deletions apps/cli/src/tasks/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,34 @@ export const ValidateTask = (): ListrTask<{
}> => ({
title: 'Validate configuration against backend',
task: async (ctx) => {
if (!ctx.backend.supportValidate) {
throw new Error(
'Validate is not supported by the current backend',
);
}
if (!ctx.backend.validate)
throw new Error(`Validate is not supported by the current backend.`);

const supported = await ctx.backend.supportValidate();
if (!supported) {
const version = await ctx.backend.version();
throw new Error(
`Validate is not supported by the current backend version (${version}). Please upgrade to a newer version.`,
);
}
const result = await lastValueFrom(ctx.backend.validate(ctx.diff));
if (result.success) return;

const result = await lastValueFrom(ctx.backend.validate!(ctx.diff));
if (!result.success) {
const lines: string[] = [];
if (result.errorMessage) {
lines.push(result.errorMessage);
}
for (const e of result.errors) {
const parts: string[] = [e.resource_type];
if (e.resource_name) {
parts.push(`name="${e.resource_name}"`);
} else {
if (e.resource_id) parts.push(`id="${e.resource_id}"`);
if (e.index !== undefined) parts.push(`index=${e.index}`);
}
lines.push(` - [${parts.join(', ')}]: ${e.error}`);
}
const error = new Error(
`Configuration validation failed:\n${lines.join('\n')}`,
);
error.stack = '';
throw error;
}
throw buildPlainTextError(result);
},
});

function buildPlainTextError(res: ADCSDK.BackendValidateResult) {
const lines: string[] = [];
if (res.errorMessage) {
lines.push(res.errorMessage);
}
for (const e of res.errors) {
const parts: string[] = [e.resource_type];
if (e.resource_name) {
parts.push(`name="${e.resource_name}"`);
} else {
if (e.resource_id) parts.push(`id="${e.resource_id}"`);
if (e.index !== undefined) parts.push(`index=${e.index}`);
}
lines.push(` - [${parts.join(', ')}]: ${e.error}`);
}
const error = new Error(
`Configuration validation failed:\n${lines.join('\n')}`,
);
error.stack = '';
return error;
}
Loading
Loading