fix: catch truncation errors when setting the display name

fixes incorrectly showing shorter display name error in integration tests
pull/3281/head
yougotwill 4 months ago
parent cffbd48c5a
commit f9ccc317b6

@ -33,6 +33,7 @@ import { resetRegistration } from '../RegistrationStages';
import { ContinueButton, OnboardDescription, OnboardHeading } from '../components';
import { BackButtonWithinContainer } from '../components/BackButton';
import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils';
import { localize } from '../../../util/i18n/localizedString';
export type AccountDetails = {
recoveryPassword: string;
@ -106,9 +107,21 @@ export const CreateAccount = () => {
`[onboarding] create account: signUpWithDetails failed! Error: ${err.message || String(err)}`
);
dispatch(setAccountCreationStep(AccountCreation.DisplayName));
// Note: we have to assume here that libsession threw an error because the name was too long.
switch (err.message) {
case 'failed to retrieve display name after setting it':
dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString()));
return;
case 'failed to get truncated displayName after setting it':
dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString()));
return;
default:
// we can't guarantee that an error has a message so we handle the final case outside of the switch
}
// Note: we have to assume here that libsession threw an error because the name was too long since we covered the other cases.
// The error reported by libsession is not localized
dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
dispatch(setDisplayNameError(localize('displayNameErrorDescriptionShorter').toString()));
}
};

@ -43,6 +43,7 @@ import { BackButtonWithinContainer } from '../components/BackButton';
import { useRecoveryProgressEffect } from '../hooks';
import { displayNameIsValid, sanitizeDisplayNameOrToast } from '../utils';
import { AccountDetails } from './CreateAccount';
import { localize } from '../../../util/i18n/localizedString';
type AccountRestoreDetails = AccountDetails & { dispatch: Dispatch; abortSignal?: AbortSignal };
@ -197,9 +198,20 @@ export const RestoreAccount = () => {
);
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
// Note: we have to assume here that libsession threw an error because the name was too long.
switch (err.message) {
case 'failed to retrieve display name after setting it':
dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString()));
return;
case 'failed to get truncated displayName after setting it':
dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString()));
return;
default:
// we can't guarantee that an error has a message so we handle the final case outside of the switch
}
// Note: we have to assume here that libsession threw an error because the name was too long since we covered the other cases.
// The error reported by libsession is not localized
dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
dispatch(setDisplayNameError(localize('displayNameErrorDescriptionShorter').toString()));
}
};

@ -115,9 +115,7 @@ async function updateOurProfileDisplayNameOnboarding(newName: string) {
const appliedName = await UserConfigWrapperActions.getName();
if (isNil(appliedName)) {
throw new Error(
'updateOurProfileDisplayNameOnboarding failed to retrieve name after setting it'
);
throw new Error('failed to retrieve display name after setting it');
}
return appliedName;
@ -143,7 +141,7 @@ async function updateOurProfileDisplayName(newName: string) {
await UserConfigWrapperActions.setNameTruncated(sanitizeSessionUsername(newName).trim());
const truncatedName = await UserConfigWrapperActions.getName();
if (isNil(truncatedName)) {
throw new Error('updateOurProfileDisplayName: failed to get truncated displayName back');
throw new Error('failed to get truncated displayName after setting it');
}
await UserConfigWrapperActions.setPriority(dbPriority);
if (dbProfileUrl && !isEmpty(dbProfileKey)) {

Loading…
Cancel
Save