Skip to content

Commit

Permalink
Improve error typing, fix assignment hint update
Browse files Browse the repository at this point in the history
  • Loading branch information
elsmr committed Apr 11, 2024
1 parent e1c9694 commit aa53f85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ const assignmentTypeToNodeProperty = (
}
};
function getExpressionResult(value: string): Result<unknown, unknown> {
try {
const resolvedValue = resolveExpression(value, {
targetItem: ndvStore.hoveringItem ?? undefined,
inputNodeName: ndvStore.ndvInputNodeName,
inputRunIndex: ndvStore.ndvInputRunIndex,
inputBranchIndex: ndvStore.ndvInputBranchIndex,
}) as unknown;
return { ok: true, result: resolvedValue };
} catch (error) {
return { ok: false, error };
}
}
const nameParameter = computed<INodeProperties>(() => ({
name: 'name',
displayName: 'Name',
Expand All @@ -95,7 +80,22 @@ const hint = computed(() => {
if (typeof value !== 'string' || !value.startsWith('=')) {
return '';
}
return stringifyExpressionResult(getExpressionResult(value));
let result: Result<unknown, Error>;
try {
const resolvedValue = resolveExpression(value, undefined, {
targetItem: ndvStore.hoveringItem ?? undefined,
inputNodeName: ndvStore.ndvInputNodeName,
inputRunIndex: ndvStore.ndvInputRunIndex,
inputBranchIndex: ndvStore.ndvInputBranchIndex,
}) as unknown;
result = { ok: true, result: resolvedValue };
} catch (error) {
result = { ok: false, error };
}
return stringifyExpressionResult(result);
});
const highlightHint = computed(() =>
Expand Down
5 changes: 3 additions & 2 deletions packages/editor-ui/src/components/ParameterInputWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ export default defineComponent({
isInputParentOfActiveNode(): boolean {
return this.ndvStore.isInputParentOfActiveNode;
},
evaluatedExpression(): Result<unknown, unknown> {
evaluatedExpression(): Result<unknown, Error> {
const value = isResourceLocatorValue(this.modelValue)
? this.modelValue.value
: this.modelValue;
if (!this.activeNode || !this.isValueExpression || typeof value !== 'string') {
return { ok: false, error: '' };
return { ok: false, error: new Error() };
}
try {
Expand Down
6 changes: 2 additions & 4 deletions packages/editor-ui/src/utils/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,13 @@ export const getExpressionErrorMessage = (error: Error): string => {
return error.message;
};

export const stringifyExpressionResult = (result: Result<unknown, unknown>): string => {
export const stringifyExpressionResult = (result: Result<unknown, Error>): string => {
if (!result.ok) {
if (getResolvableState(result.error) !== 'invalid') {
return '';
}

return `[${i18n.baseText('parameterInput.error')}: ${getExpressionErrorMessage(
result.error as Error,
)}]`;
return `[${i18n.baseText('parameterInput.error')}: ${getExpressionErrorMessage(result.error)}]`;
}

if (result.result === null) {
Expand Down

0 comments on commit aa53f85

Please sign in to comment.