Make app command parse error message more readable (#5238)

* Make app command parse error message more readable

* Update i18n
This commit is contained in:
Daniel Espino García 2021-03-29 13:04:08 +02:00 committed by GitHub
parent b4a97f13a8
commit 26ffdbde91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View file

@ -37,6 +37,7 @@ import {
getChannelByNameAndTeamName,
getCurrentTeam,
selectChannelByName,
errorMessage as parserErrorMessage,
} from './app_command_parser_dependencies';
export type Store = {
@ -100,17 +101,6 @@ export class ParsedCommand {
return this;
};
errorMessage = (): string => {
return this.intl.formatMessage({
id: 'apps.error.parser',
defaultMessage: 'Parsing error: {error}.\n```\n{command}\n{space}^\n```',
}, {
error: this.error,
command: this.command,
space: ' '.repeat(this.i),
});
}
// matchBinding finds the closest matching command binding.
matchBinding = async (commandBindings: AppBinding[], autocompleteMode = false): Promise<ParsedCommand> => {
if (commandBindings.length === 0) {
@ -568,7 +558,7 @@ export class AppCommandParser {
parsed = await parsed.matchBinding(commandBindings, false);
parsed = parsed.parseForm(false);
if (parsed.state === ParseState.Error) {
return {call: null, errorMessage: parsed.errorMessage()};
return {call: null, errorMessage: parserErrorMessage(this.intl, parsed.error, parsed.command, parsed.i)};
}
const missing = this.getMissingFields(parsed);

View file

@ -76,3 +76,12 @@ export const displayError = (intl: typeof intlShape, body: string) => {
});
Alert.alert(title, body);
};
export const errorMessage = (intl: typeof intlShape, error: string, _command: string, _position: number): string => { // eslint-disable-line @typescript-eslint/no-unused-vars
return intl.formatMessage({
id: 'apps.error.parser',
defaultMessage: 'Parsing error: {error}',
}, {
error,
});
};

View file

@ -24,7 +24,7 @@
"apps.error.form.refresh_no_refresh": "Called refresh on no refresh field.",
"apps.error.form.submit.pretext": "There has been an error submitting the modal. Contact the app developer. Details: {details}",
"apps.error.lookup.error_preparing_request": "Error preparing lookup request: {errorMessage}",
"apps.error.parser": "Parsing error: {error}.\n```\n{command}\n{space}^\n```",
"apps.error.parser": "Parsing error: {error}",
"apps.error.parser.empty_value": "empty values are not allowed",
"apps.error.parser.missing_binding": "Missing command bindings.",
"apps.error.parser.missing_call": "Missing binding call.",