Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error throwing in save message #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

owenboy9
Copy link
Collaborator

@owenboy9 owenboy9 commented Jan 19, 2025

Description

fix error thrown on saving translation
prior to the fix, on click on save, it only kept 'thinking' forever

Changes

replace 'throw' with a return error message object

Notes to reviewer

thank you for all your help
tested the issue by changing the if statement to if (true) in order to see the error no matter what

Related issues

Resolves #146

Copy link
Collaborator

@WULCAN WULCAN left a comment

Choose a reason for hiding this comment

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

Thank you, I approve of merging this pull request. I've noted a couple of further improvements that I think we will want to do, but we can defer those to a later pull request.

@@ -85,7 +85,12 @@ export default async function updateTranslation(
const foundId = messageIds.find((id) => id == messageId);

if (foundId === undefined) {
throw new MessageNotFound(languageName, messageId);
Copy link
Collaborator

@WULCAN WULCAN Jan 25, 2025

Choose a reason for hiding this comment

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

This was the only use of MessageNotFound

export class MessageNotFound extends Error {
constructor(lang: string, msgId: string) {
super(`Message ${msgId} for language ${lang} not found`);
}
}

Removing the last usage is an excellent opportunity to also remove the unused source code. I believe unused source code makes the project harder to maintain.

Let's remember to remove MessageNotFound after merging this pull request.

@@ -85,7 +85,12 @@ export default async function updateTranslation(
const foundId = messageIds.find((id) => id == messageId);

if (foundId === undefined) {
throw new MessageNotFound(languageName, messageId);
return {
errorMessage: 'Message Id not found',
Copy link
Collaborator

Choose a reason for hiding this comment

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

The value for errorMessage is what will be displayed to the user.

<Alert
onClose={onDismissSnackbar}
severity="error"
sx={{ width: '100%' }}
variant="filled"
>
{state.errorMessage}
</Alert>

'Failed to update translation' is not a very helpful error message to the user. What can she do with that information? Still, it is much better than the save button just animating forever.

Let's remember to improve this further after merging this pull request.

WULCAN added a commit that referenced this pull request Jan 25, 2025
Configure ESLint to warn instead of fail the build on unused variables.

In #152 this rule blocks merging even
though the added value from the pull request by far outweighs the
introduced inconvenience. The reviewer can decide for herself instead
wether unused variables needs to be fixed before or after merging.
@WULCAN WULCAN mentioned this pull request Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle errors in updateTranslation
2 participants