Merge pull request #32 from yougotwill/fix/ses-2668/integration_test_fixes

fix: catch truncation errors when setting the display name
pull/3281/head
Audric Ackermann 4 months ago committed by GitHub
commit 252f98242d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -33,6 +33,8 @@ 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';
import { RetrieveDisplayNameError } from '../../../session/utils/errors';
export type AccountDetails = {
recoveryPassword: string;
@ -106,9 +108,15 @@ 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.
if (err instanceof RetrieveDisplayNameError) {
dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString()));
return;
}
// 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()));
}
};

@ -6,7 +6,7 @@ import { InvalidWordsError, NotEnoughWordsError } from '../../../session/crypto/
import { ProfileManager } from '../../../session/profile_manager/ProfileManager';
import { PromiseUtils } from '../../../session/utils';
import { TaskTimedOutError } from '../../../session/utils/Promise';
import { NotFoundError } from '../../../session/utils/errors';
import { NotFoundError, RetrieveDisplayNameError } from '../../../session/utils/errors';
import { trigger } from '../../../shims/events';
import {
AccountRestoration,
@ -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,14 @@ export const RestoreAccount = () => {
);
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
// Note: we have to assume here that libsession threw an error because the name was too long.
if (err instanceof RetrieveDisplayNameError) {
dispatch(setDisplayNameError(localize('displayNameErrorDescription').toString()));
return;
}
// 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()));
}
};

@ -6,6 +6,7 @@ import { SyncUtils, UserUtils } from '../utils';
import { fromHexToArray, sanitizeSessionUsername, toHex } from '../utils/String';
import { AvatarDownload } from '../utils/job_runners/jobs/AvatarDownloadJob';
import { CONVERSATION_PRIORITIES, ConversationTypeEnum } from '../../models/types';
import { RetrieveDisplayNameError } from '../utils/errors';
export type Profile = {
displayName: string | undefined;
@ -115,9 +116,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 RetrieveDisplayNameError();
}
return appliedName;
@ -143,7 +142,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 RetrieveDisplayNameError();
}
await UserConfigWrapperActions.setPriority(dbPriority);
if (dbProfileUrl && !isEmpty(dbProfileKey)) {

@ -74,3 +74,11 @@ export class SnodeResponseError extends Error {
Object.setPrototypeOf(this, SnodeResponseError.prototype);
}
}
export class RetrieveDisplayNameError extends Error {
constructor(message = 'failed to retrieve display name after setting it') {
super(message);
// restore prototype chain
Object.setPrototypeOf(this, SnodeResponseError.prototype);
}
}

Loading…
Cancel
Save