Skip to content

fix: tts node and stt node add warning#1953

Merged
wxg0103 merged 1 commit intomainfrom
pr@main@fix_1050722
Dec 31, 2024
Merged

fix: tts node and stt node add warning#1953
wxg0103 merged 1 commit intomainfrom
pr@main@fix_1050722

Conversation

@shaohuzhang1
Copy link
Contributor

fix: tts node and stt node add warning --bug=1050722 --user=็Ž‹ๅญๅˆš ใ€ๅบ”็”จ็ผ–ๆŽ’ใ€‘ๅ‰็ฝฎ่Š‚็‚นๅˆ ๆމๅŽ๏ผŒ่ฐƒ่ฏ•ๅ’Œๅ‘ๅธƒ็š„ๆ—ถๅ€™ๅผ•็”จๅ‰็ฝฎ่Š‚็‚น็š„ๅ˜้‡่ฆๆœ‰ๆ็คบ https://www.tapd.cn/57709429/s/1639310

--bug=1050722 --user=็Ž‹ๅญๅˆš ใ€ๅบ”็”จ็ผ–ๆŽ’ใ€‘ๅ‰็ฝฎ่Š‚็‚นๅˆ ๆމๅŽ๏ผŒ่ฐƒ่ฏ•ๅ’Œๅ‘ๅธƒ็š„ๆ—ถๅ€™ๅผ•็”จๅ‰็ฝฎ่Š‚็‚น็š„ๅ˜้‡่ฆๆœ‰ๆ็คบ https://www.tapd.cn/57709429/s/1639310
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 31, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 31, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wxg0103 wxg0103 merged commit 7055cbc into main Dec 31, 2024
4 checks passed
@wxg0103 wxg0103 deleted the pr@main@fix_1050722 branch December 31, 2024 01:38
]).catch((err: any) => {
return Promise.reject({ node: props.nodeModel, errMessage: err })
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code is mostly correct, but there are a few improvements that can be made:

  1. Avoid Using Await with Promise.all: The use of await inside the catch block will prevent further execution after an error. Replace it with .then() to continue processing.

  2. Ensure Cascader Validations: Ensure that cascader validations handle cases where the reference might not exist (as it does now).

Here's the revised version of the code:

@@ -145,6 +145,7 @@ import { app } from '@/main'
 import useStore from '@/stores'
 import NodeCascader from '@/workflow/common/NodeCascader.vue'
 import type { FormInstance } from 'element-plus'

+import { onMounted, ref } from 'vue';
+
 const { model } = useStore();

 // Assuming props.nodeModel exists
 const modelOptions = ref<any[]>([]);
 const providerOptions = ref<Array<Provider>>([]);

 const aiChatNodeFormRef = ref<FormInstance>();
+const nodeCascaderRef = ref(null); // Initialize as null

// Assume this function initializes the form and cascade components
function initializeFormAndCascade() {
  onMounted(() => {
    if (nodeCascaderRef.value) {
      nodeCascaderRef.value.resetFields();
    }
    
    if (aiChatNodeFormRef.value) {
      aiChatNodeFormRef.value.clearValidate()
    }
  });
}

const validate = () => {
  return new Promise((resolve) => {
    Promise.all([
        nodeCascaderRef.value ? nodeCascaderRef.value.validate() : "",
        aiChatNodeFormRef.value?.validate(e => resolve(!e))
    ])
    .catch(err => reject({ node: props.nodeModel, errMessage: err }))
  })
}

Key Changes:

  • Await Removal: Replaced async/await syntax with traditional promises using new Promise.
  • Null Initialization: Initialized nodeCascaderRef as null. This ensures we don't rely on optional chaining (?) unnecessarily and avoids potential runtime errors.
  • Initialization Hook: Added a setup function called initializeFormAndCascade, which uses Vue's onMounted hook to ensure that any necessary initialization logic runs once the component has mounted.

This should address most performance concerns and improve stability.

]).catch((err: any) => {
return Promise.reject({ node: props.nodeModel, errMessage: err })
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no critical errors in the provided code. However, I suggest adding error handling to ensure that the nodeCascader validation does not prevent the form from being validated at all. Hereโ€™s an optimized version:

const modelOptions = ref<any>(null);
const providerOptions = ref<Array<Provider>>([]);

const aiChatNodeFormRef = ref<FormInstance>();
const nodeCascaderRef = ref();

function validate(): Promise<{ message?: string }> {
  return Promise.race([
    (async () => await (nodeCascaderRef.value && nodeCascaderRef.value.validate()))(),
    (async () => await (aiChatNodeFormRef.value && aiChatNodeFormRef.value.validate()))()
  ])
  .catch((err) => ({ message: err }));
}

Key Changes:

  1. Error Handling: Used .catch((err) => ({ message: err })) to handle any errors and provide a consistent response format.
  2. Promise.all with Race Condition: Utilized Promise.race() to ensure that if either validator fails, it is caught quickly without impacting the other.
  3. Async/Await Simplification: Slightly simplified the promise chaining for better readability.

This approach ensures that both validators run concurrently, but stops execution on the first successful result or the first error encountered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants