-
Notifications
You must be signed in to change notification settings - Fork 1
enhanced error logging #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/generateTS/factory.ts
Outdated
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`; | ||
}); |
There was a problem hiding this comment.
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.
src/generateTS/factory.ts
Outdated
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, | ||
}; |
There was a problem hiding this comment.
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.
No description provided.