Skip to content

Commit

Permalink
fix(Consumption): Changing error message for invalid expression due t…
Browse files Browse the repository at this point in the history
…o double quotes. (#4141)

* double quote check in concat call under compose

* making the catch more general with regex

* changing it to catch more errors with double quote

* changing from 'quote' to 'quotes' in error message

* throwing new error if misused double quotes

* adjusting message description

* updating comment

* fixing wording
  • Loading branch information
valentina-vallalta committed Feb 13, 2024
1 parent 4ba6a0c commit cddc9a2
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 26 deletions.
6 changes: 4 additions & 2 deletions Localize/lang/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@
"H2WdiZ": "Enter the valid minute values (from 0 to 59) separated by comma, e.g., 15,30",
"H5VikC": "Invalid connection, mapping must not form a closed loop.",
"H8bEUn": "Required. The number that Subtrahend is removed from.",
"H9CZTr": "The expression is invalid. Make sure to use single quotes.",
"HDqP2g": "Required. The key name of the form data value to return.",
"HH970i": "Month",
"HILmmE": "Required. The collection to sort.",
Expand Down Expand Up @@ -1349,6 +1350,7 @@
"_H2WdiZ.comment": "Placeholder for schedule minutes",
"_H5VikC.comment": "Error message for circular logic connection validation",
"_H8bEUn.comment": "Required number parameter to be minused in sub function",
"_H9CZTr.comment": "Invalid expression due to misused double quotes",
"_HDqP2g.comment": "Required string parameter to be used as key for triggerFormDataValue function",
"_HH970i.comment": "Frequency value ",
"_HILmmE.comment": "Required collection parameter to apply sort function on",
Expand Down Expand Up @@ -2250,6 +2252,7 @@
"_sys5gu.comment": "Authentication type",
"_sytRna.comment": "Error message to show when loading dynamic inputs failed",
"_t+XCkg.comment": "Required string parameter for destination time zone",
"_t9RwOi.comment": "Invalid expression alert",
"_tAbbH8.comment": "Title for a too many inputs card",
"_tAeKNh.comment": "Function display radio group option for simple",
"_tE7Zam.comment": "Label for description of custom listCallbackUrl Function",
Expand Down Expand Up @@ -2316,7 +2319,6 @@
"_vQcQkU.comment": "Required text parameter to search endsWith function with",
"_vSlNPe.comment": "Delete text",
"_vT0DCP.comment": "Display name for operation outputs",
"_vVJuus.comment": "invalid expression alert",
"_vX9WYS.comment": "Audience Label Display Name",
"_va40BJ.comment": "Required string parameter to determine action's output wanted",
"_vdKLiR.comment": "An accessability label that describes the settings tab",
Expand Down Expand Up @@ -2874,6 +2876,7 @@
"sys5gu": "Client Certificate",
"sytRna": "Failed to retrieve dynamic inputs. Error details: ''{message}''",
"t+XCkg": "Required. A string that contains the time zone name of the destination time zone. See https://msdn.microsoft.com/en-us/library/gg154758.aspx for details.",
"t9RwOi": "The expression is invalid.",
"tAbbH8": "Too many inputs assigned",
"tAeKNh": "Simple",
"tE7Zam": "Returns the URL to invoke the trigger or action",
Expand Down Expand Up @@ -2940,7 +2943,6 @@
"vQcQkU": "Required. The value the string may end with.",
"vSlNPe": "Delete",
"vT0DCP": "Outputs",
"vVJuus": "The expression is invalid.",
"vX9WYS": "Audience",
"va40BJ": "Required. The name of the action whose outputs you want.",
"vdKLiR": "Request Settings",
Expand Down
15 changes: 12 additions & 3 deletions libs/designer-ui/src/lib/tokenpicker/tokenpickerfooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getExpressionTokenTitle, getExpressionOutput } from './util';
import { PrimaryButton } from '@fluentui/react';
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import type { Expression } from '@microsoft/parsers-logic-apps';
import { ExpressionParser } from '@microsoft/parsers-logic-apps';
import { ExpressionExceptionCode, ExpressionParser, ScannerException } from '@microsoft/parsers-logic-apps';
import { guid } from '@microsoft/utils-logic-apps';
import type { LexicalEditor, NodeKey } from 'lexical';
import { useMemo } from 'react';
Expand Down Expand Up @@ -68,7 +68,11 @@ export function TokenPickerFooter({
});
const invalidExpression = intl.formatMessage({
defaultMessage: 'The expression is invalid.',
description: 'invalid expression alert',
description: 'Invalid expression alert',
});
const invalidExpressionQuotations = intl.formatMessage({
defaultMessage: 'The expression is invalid. Make sure to use single quotes.',
description: 'Invalid expression due to misused double quotes',
});

const insertToken = (tokenProps: TokenNodeProps) => {
Expand Down Expand Up @@ -96,7 +100,12 @@ export function TokenPickerFooter({
try {
currExpression = ExpressionParser.parseExpression(expression.value);
} catch (ex) {
setExpressionEditorError(invalidExpression);
if (ex instanceof ScannerException && ex.message === ExpressionExceptionCode.MISUSED_DOUBLE_QUOTES) {
// if the expression contains misused double quotes, we'll show a different error message
setExpressionEditorError(invalidExpressionQuotations);
} else {
setExpressionEditorError(invalidExpression);
}
return;
}
if (expression.value && window.localStorage.getItem('msla-tokenpicker-expression') !== expression.value) {
Expand Down
1 change: 1 addition & 0 deletions libs/parsers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './lib/resolution-service/resolution-service';
export * from './lib/common/constants';
export * from './lib/common/exceptions/expression';
export * from './lib/common/exceptions/parser';
export * from './lib/common/exceptions/scanner';
1 change: 1 addition & 0 deletions libs/parsers/src/lib/common/exceptions/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const ExpressionExceptionCode = {
STRING_LITERAL_NOT_TERMINATED: 'StringLiteralNotTerminated',
TOKEN_NOT_FOUND: 'TokenNotFound',
UNEXPECTED_CHARACTER: 'UnexpectedCharacter',
MISUSED_DOUBLE_QUOTES: 'MisusedDoubleQuotes',
} as const;
export type ExpressionExceptionCode = (typeof ExpressionExceptionCode)[keyof typeof ExpressionExceptionCode];

Expand Down
6 changes: 5 additions & 1 deletion libs/parsers/src/lib/expression/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export class ExpressionScanner {
if (equals(ch, '+') || equals(ch, '-') || isNumeric(ch)) {
return this._processAndGetTokenForNumber(currentPos);
} else if (this._isSupportedIdentifierCharacter(ch)) {
return this._processAndGetTokenForIdentifier(currentPos);
const token = this._processAndGetTokenForIdentifier(currentPos);
if (token.value.startsWith('"') && token.value.endsWith('"')) {
throw new ScannerException(ExpressionExceptionCode.MISUSED_DOUBLE_QUOTES, ExpressionExceptionCode.MISUSED_DOUBLE_QUOTES);
}
return token;
} else {
throw new ScannerException(ExpressionExceptionCode.UNEXPECTED_CHARACTER, ExpressionExceptionCode.UNEXPECTED_CHARACTER);
}
Expand Down
42 changes: 28 additions & 14 deletions libs/services/intl/src/compiled-lang/strings.en-XA.json
Original file line number Diff line number Diff line change
Expand Up @@ -6569,6 +6569,20 @@
"value": "]"
}
],
"H9CZTr": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Ŧħḗḗ ḗḗẋƥřḗḗşşīǿǿƞ īş īƞṽȧȧŀīḓ. Ḿȧȧķḗḗ şŭŭřḗḗ ŧǿǿ ŭŭşḗḗ şīƞɠŀḗḗ ɋŭŭǿǿŧḗḗş."
},
{
"type": 0,
"value": "]"
}
],
"HDqP2g": [
{
"type": 0,
Expand Down Expand Up @@ -19797,6 +19811,20 @@
"value": "]"
}
],
"t9RwOi": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Ŧħḗḗ ḗḗẋƥřḗḗşşīǿǿƞ īş īƞṽȧȧŀīḓ."
},
{
"type": 0,
"value": "]"
}
],
"tAbbH8": [
{
"type": 0,
Expand Down Expand Up @@ -20761,20 +20789,6 @@
"value": "]"
}
],
"vVJuus": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Ŧħḗḗ ḗḗẋƥřḗḗşşīǿǿƞ īş īƞṽȧȧŀīḓ."
},
{
"type": 0,
"value": "]"
}
],
"vX9WYS": [
{
"type": 0,
Expand Down
18 changes: 12 additions & 6 deletions libs/services/intl/src/compiled-lang/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,12 @@
"value": "Required. The number that Subtrahend is removed from."
}
],
"H9CZTr": [
{
"type": 0,
"value": "The expression is invalid. Make sure to use single quotes."
}
],
"HDqP2g": [
{
"type": 0,
Expand Down Expand Up @@ -8997,6 +9003,12 @@
"value": "Required. A string that contains the time zone name of the destination time zone. See https://msdn.microsoft.com/en-us/library/gg154758.aspx for details."
}
],
"t9RwOi": [
{
"type": 0,
"value": "The expression is invalid."
}
],
"tAbbH8": [
{
"type": 0,
Expand Down Expand Up @@ -9433,12 +9445,6 @@
"value": "Outputs"
}
],
"vVJuus": [
{
"type": 0,
"value": "The expression is invalid."
}
],
"vX9WYS": [
{
"type": 0,
Expand Down

0 comments on commit cddc9a2

Please sign in to comment.