Skip to content

Conversation

naman-contentstack
Copy link
Contributor

No description provided.

@naman-contentstack naman-contentstack self-assigned this Aug 12, 2025
@naman-contentstack naman-contentstack requested a review from a team as a code owner August 12, 2025 07:11
aman19K
aman19K previously approved these changes Aug 12, 2025
@naman-contentstack naman-contentstack marked this pull request as draft August 13, 2025 11:47
@naman-contentstack naman-contentstack marked this pull request as ready for review August 14, 2025 07:15
@naman-contentstack naman-contentstack merged commit f5a8a58 into development Aug 25, 2025
9 checks passed
@naman-contentstack naman-contentstack deleted the enhancement/DX-3404 branch August 25, 2025 05:36
Comment on lines 622 to 637
contentTypeErrors.forEach((error, index) => {
errorDetails += `${index + 1}. UID: "${error.uid}"\n`;
errorDetails += ` Reason: ${NUMERIC_IDENTIFIER_EXCLUSION_REASON}\n`;
errorDetails += ` Suggestion: Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")\n\n`;
});
}

if (globalFieldErrors.length > 0) {
errorDetails += "Global Fields Referencing Invalid Content Types:\n\n";

globalFieldErrors.forEach((error, index) => {
errorDetails += `${index + 1}. Global Field: "${error.uid}"\n`;
errorDetails += ` References: "${error.referenceTo || "Unknown"}"\n`;
errorDetails += ` Reason: ${NUMERIC_IDENTIFIER_EXCLUSION_REASON}\n`;
errorDetails += ` Suggestion: Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")\n\n`;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naman-contentstack , The code inside both loops is quite similar and repetitive. It would be better to move the common logic into a shared function like formatErrorDetails to improve readability and reduce duplication.

Comment on lines 604 to 650
if (numericIdentifierErrors.length > 0) {
// Group errors by type for better organization
const contentTypeErrors = numericIdentifierErrors.filter(
(err) => err.type === "content_type"
);
const globalFieldErrors = numericIdentifierErrors.filter(
(err) => err.type === "global_field"
);

// Build the detailed error message
let errorDetails = "";
errorDetails += `Type generation failed: Found ${numericIdentifierErrors.length} items with numeric identifiers that create invalid TypeScript interface names. Please use the --prefix flag to resolve this issue.\n\n`;

if (contentTypeErrors.length > 0) {
errorDetails += "Content Types & Global Fields with Numeric UIDs:\n";
errorDetails +=
"Note: Global Fields are Content Types, so they appear in this section if their own UID starts with a number.\n\n";

contentTypeErrors.forEach((error, index) => {
errorDetails += `${index + 1}. UID: "${error.uid}"\n`;
errorDetails += ` Reason: ${NUMERIC_IDENTIFIER_EXCLUSION_REASON}\n`;
errorDetails += ` Suggestion: Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")\n\n`;
});
}

if (globalFieldErrors.length > 0) {
errorDetails += "Global Fields Referencing Invalid Content Types:\n\n";

globalFieldErrors.forEach((error, index) => {
errorDetails += `${index + 1}. Global Field: "${error.uid}"\n`;
errorDetails += ` References: "${error.referenceTo || "Unknown"}"\n`;
errorDetails += ` Reason: ${NUMERIC_IDENTIFIER_EXCLUSION_REASON}\n`;
errorDetails += ` Suggestion: Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType")\n\n`;
});
}

errorDetails += "To resolve these issues:\n";
errorDetails +=
" • Use the --prefix flag to add a valid prefix to all interface names\n";
errorDetails += " • Example: --prefix 'ContentType'\n";

// Throw a comprehensive error with all the details
throw {
type: "validation",
error_code: "VALIDATION_ERROR",
error_message: errorDetails,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naman-contentstack , Break this logic into multiple methods and organize them within a parent method. Then, call the parent method here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants