-
-
Notifications
You must be signed in to change notification settings - Fork 381
chore: add error handling to generator components #2003
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
base: master
Are you sure you want to change the base?
Changes from all commits
dd2b200
580a06c
e297b40
1c70d9b
05104c8
50f82a9
8cf856b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||
| import { Text } from '@asyncapi/generator-react-sdk'; | ||||
| import { unsupportedLanguage, negativeIndent, invalidMethodName, invalidNewLines, invalidMethodParams } from '../utils/ErrorHandling'; | ||||
|
|
||||
| /** | ||||
| * @typedef {'python' | 'javascript' | 'dart' | 'java'} Language | ||||
|
|
@@ -75,18 +76,19 @@ const buildIndentedLogic = (logic, preExecutionCode, postExecutionCode, indentSi | |||
| * | ||||
| * @param {Object} props - Component props. | ||||
| * @param {Language} props.language - Programming language used for method formatting. | ||||
| * @param {string} props.methodName - Name of the method. | ||||
| * @param {string} props.methodName - Name of the method (non-empty string required). | ||||
| * @param {string[]} [props.methodParams=[]] - Method parameters. | ||||
| * @param {string} [props.methodDocs=''] - Optional documentation string. | ||||
| * @param {string} [props.methodLogic=''] - Core method logic. | ||||
| * @param {string} [props.preExecutionCode=''] - Code before main logic. | ||||
| * @param {string} [props.postExecutionCode=''] - Code after main logic. | ||||
| * @param {number} [props.indent=2] - Indentation for the method block. | ||||
| * @param {number} [props.indent=2] - Indentation for the method block (must be >= 0). | ||||
| * @param {number} [props.newLines=1] - Number of new lines after method. | ||||
| * @param {{ returnType: string | undefined, openingTag: string | undefined, closingTag: string | undefined, indentSize: number | undefined, parameterWrap: boolean | undefined }} [props.customMethodConfig] - Optional custom syntax configuration for the current language. | ||||
| * @param {{ returnType: string | undefined, openingTag: string | undefined, closingTag: string | undefined, indentSize: number | undefined, parameterWrap: boolean | undefined }} [props.customMethodConfig] - Optional custom syntax configuration for the current language. | ||||
| * @param {Record<Language, { methodDocs: string | undefined, methodLogic: string | undefined } | Record<string, { methodDocs: string | undefined, methodLogic: string | undefined }>>} [props.methodConfig] - Language-level or framework-level configuration. | ||||
| * @param {string} [props.framework] - Framework name for nested configurations (e.g., 'quarkus' for Java). | ||||
| * @returns {JSX.Element} A Text component that contains method block with appropriate formatting. | ||||
| * @throws {Error} If language is unsupported, methodName is invalid, or indent is negative. | ||||
| * | ||||
| * @example | ||||
| * const language = "java"; | ||||
|
|
@@ -133,6 +135,28 @@ export function MethodGenerator({ | |||
| methodConfig, | ||||
| framework | ||||
| }) { | ||||
| const supportedLanguages = Object.keys(defaultMethodConfig); | ||||
|
|
||||
| if (!supportedLanguages.includes(language)) { | ||||
| throw unsupportedLanguage(language, supportedLanguages); | ||||
| } | ||||
|
|
||||
| if (typeof methodName !== 'string') { | ||||
| throw invalidMethodName(); | ||||
| } | ||||
|
Comment on lines
+144
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Two issues:
Suggested fix- if (typeof methodName !== 'string') {
- throw invalidMethodName();
+ if (typeof methodName !== 'string' || methodName.trim() === '') {
+ throw invalidMethodName(methodName);
}🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Adi-204 I'm a little bit confused here, because in generator/packages/templates/clients/websocket/java/quarkus/components/InitConnector.js Line 21 in 2267f02
We are calling CloseConnection, which in turn calls the methodGenerator with an empty string as the methodName.
What do you suggest?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @batchu5 honestly I don't have much idea as the template was develop during last year GSoC project by other guy. It also depends what params for a component you are keeping as optional/required and logic inside the component.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @batchu5 one imp thing remember you will have to look at how components are used in different templates and decide which params of component are required or optional. As you can't make every param as required becoz than it would fail for some templates.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay @Adi-204
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment, I'll keep it as it is! |
||||
|
|
||||
| if (indent < 0) { | ||||
| throw negativeIndent(indent); | ||||
| } | ||||
|
|
||||
| if (newLines < 0) { | ||||
| throw invalidNewLines(newLines); | ||||
| } | ||||
|
|
||||
| if (!Array.isArray(methodParams)) { | ||||
| throw invalidMethodParams(methodParams); | ||||
| } | ||||
|
|
||||
| const { docs: resolvedMethodDocs, logic: resolvedMethodLogic } = resolveDocsAndLogic({ | ||||
| language, | ||||
| methodDocs, | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.