Przeglądaj źródła

optimize: code node has a bad error message (#3949)

Yeuoly 1 rok temu
rodzic
commit
e7b4d024ee

+ 8 - 8
api/core/workflow/nodes/code/code_node.py

@@ -141,10 +141,10 @@ class CodeNode(BaseNode):
         :return:
         """
         if not isinstance(value, str):
-            raise ValueError(f"{variable} in output form must be a string")
+            raise ValueError(f"Output variable `{variable}` must be a string")
 
         if len(value) > MAX_STRING_LENGTH:
-            raise ValueError(f'{variable} in output form must be less than {MAX_STRING_LENGTH} characters')
+            raise ValueError(f'The length of output variable `{variable}` must be less than {MAX_STRING_LENGTH} characters')
 
         return value.replace('\x00', '')
 
@@ -156,15 +156,15 @@ class CodeNode(BaseNode):
         :return:
         """
         if not isinstance(value, int | float):
-            raise ValueError(f"{variable} in output form must be a number")
+            raise ValueError(f"Output variable `{variable}` must be a number")
 
         if value > MAX_NUMBER or value < MIN_NUMBER:
-            raise ValueError(f'{variable} in input form is out of range.')
+            raise ValueError(f'Output variable `{variable}` is out of range, it must be between {MIN_NUMBER} and {MAX_NUMBER}.')
 
         if isinstance(value, float):
             # raise error if precision is too high
             if len(str(value).split('.')[1]) > MAX_PRECISION:
-                raise ValueError(f'{variable} in output form has too high precision.')
+                raise ValueError(f'Output variable `{variable}` has too high precision, it must be less than {MAX_PRECISION} digits.')
 
         return value
 
@@ -271,7 +271,7 @@ class CodeNode(BaseNode):
 
                 if len(result[output_name]) > MAX_NUMBER_ARRAY_LENGTH:
                     raise ValueError(
-                        f'{prefix}{dot}{output_name} in output form must be less than {MAX_NUMBER_ARRAY_LENGTH} characters.'
+                        f'The length of output variable `{prefix}{dot}{output_name}` must be less than {MAX_NUMBER_ARRAY_LENGTH} elements.'
                     )
 
                 transformed_result[output_name] = [
@@ -290,7 +290,7 @@ class CodeNode(BaseNode):
 
                 if len(result[output_name]) > MAX_STRING_ARRAY_LENGTH:
                     raise ValueError(
-                        f'{prefix}{dot}{output_name} in output form must be less than {MAX_STRING_ARRAY_LENGTH} characters.'
+                        f'The length of output variable `{prefix}{dot}{output_name}` must be less than {MAX_STRING_ARRAY_LENGTH} elements.'
                     )
 
                 transformed_result[output_name] = [
@@ -309,7 +309,7 @@ class CodeNode(BaseNode):
 
                 if len(result[output_name]) > MAX_OBJECT_ARRAY_LENGTH:
                     raise ValueError(
-                        f'{prefix}{dot}{output_name} in output form must be less than {MAX_OBJECT_ARRAY_LENGTH} characters.'
+                        f'The length of output variable `{prefix}{dot}{output_name}` must be less than {MAX_OBJECT_ARRAY_LENGTH} elements.'
                     )
                 
                 for i, value in enumerate(result[output_name]):

+ 1 - 1
api/tests/integration_tests/workflow/nodes/test_code.py

@@ -114,7 +114,7 @@ def test_execute_code_output_validator(setup_code_executor_mock):
     result = node.run(pool)
 
     assert result.status == WorkflowNodeExecutionStatus.FAILED
-    assert result.error == 'result in output form must be a string'
+    assert result.error == 'Output variable `result` must be a string'
 
 def test_execute_code_output_validator_depth():
     code = '''