1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-27 04:03:00 +02:00

Remove empty catch blocks, and update tslint rule (#513)

This commit is contained in:
Oscar Hinton 2021-10-19 10:32:14 +02:00 committed by GitHub
parent 62011628d0
commit f09fb69882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 228 additions and 85 deletions

View File

@ -20,6 +20,7 @@ import { CollectionService } from 'jslib-common/abstractions/collection.service'
import { EventService } from 'jslib-common/abstractions/event.service';
import { FolderService } from 'jslib-common/abstractions/folder.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
@ -88,7 +89,7 @@ export class AddEditComponent implements OnInit {
protected auditService: AuditService, protected stateService: StateService,
protected userService: UserService, protected collectionService: CollectionService,
protected messagingService: MessagingService, protected eventService: EventService,
protected policyService: PolicyService) {
protected policyService: PolicyService, private logService: LogService) {
this.typeOptions = [
{ name: i18nService.t('typeLogin'), value: CipherType.Login },
{ name: i18nService.t('typeCard'), value: CipherType.Card },
@ -283,7 +284,9 @@ export class AddEditComponent implements OnInit {
this.onSavedCipher.emit(this.cipher);
this.messagingService.send(this.editMode && !this.cloneMode ? 'editedCipher' : 'addedCipher');
return true;
} catch { }
} catch (e) {
this.logService.error(e);
}
return false;
}
@ -346,7 +349,9 @@ export class AddEditComponent implements OnInit {
this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeletedItem' : 'deletedItem'));
this.onDeletedCipher.emit(this.cipher);
this.messagingService.send(this.cipher.isDeleted ? 'permanentlyDeletedCipher' : 'deletedCipher');
} catch { }
} catch (e) {
this.logService.error(e);
}
return true;
}
@ -369,7 +374,9 @@ export class AddEditComponent implements OnInit {
this.platformUtilsService.showToast('success', null, this.i18nService.t('restoredItem'));
this.onRestoredCipher.emit(this.cipher);
this.messagingService.send('restoredCipher');
} catch { }
} catch (e) {
this.logService.error(e);
}
return true;
}

View File

@ -10,6 +10,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service';
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { UserService } from 'jslib-common/abstractions/user.service';
@ -38,7 +39,7 @@ export class AttachmentsComponent implements OnInit {
constructor(protected cipherService: CipherService, protected i18nService: I18nService,
protected cryptoService: CryptoService, protected userService: UserService,
protected platformUtilsService: PlatformUtilsService, protected apiService: ApiService,
protected win: Window) { }
protected win: Window, private logService: LogService) { }
async ngOnInit() {
await this.init();
@ -71,7 +72,9 @@ export class AttachmentsComponent implements OnInit {
this.cipher = await this.cipherDomain.decrypt();
this.platformUtilsService.showToast('success', null, this.i18nService.t('attachmentSaved'));
this.onUploadedAttachment.emit();
} catch { }
} catch (e) {
this.logService.error(e);
}
// reset file input
// ref: https://stackoverflow.com/a/20552042
@ -100,7 +103,9 @@ export class AttachmentsComponent implements OnInit {
if (i > -1) {
this.cipher.attachments.splice(i, 1);
}
} catch { }
} catch (e) {
this.logService.error(e);
}
this.deletePromises[attachment.id] = null;
this.onDeletedAttachment.emit();
@ -226,7 +231,9 @@ export class AttachmentsComponent implements OnInit {
a.downloading = false;
});
await this.reuploadPromises[attachment.id];
} catch { }
} catch (e) {
this.logService.error(e);
}
}
protected loadCipher() {

View File

@ -9,6 +9,7 @@ import {
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { CipherView } from 'jslib-common/models/view/cipherView';
@ -30,7 +31,7 @@ export class CollectionsComponent implements OnInit {
protected cipherDomain: Cipher;
constructor(protected collectionService: CollectionService, protected platformUtilsService: PlatformUtilsService,
protected i18nService: I18nService, protected cipherService: CipherService) { }
protected i18nService: I18nService, protected cipherService: CipherService, private logService: LogService) { }
async ngOnInit() {
await this.load();
@ -65,7 +66,9 @@ export class CollectionsComponent implements OnInit {
await this.formPromise;
this.onSavedCollections.emit();
this.platformUtilsService.showToast('success', null, this.i18nService.t('editedItem'));
} catch { }
} catch (e) {
this.logService.error(e);
}
}
protected loadCipher() {

View File

@ -9,6 +9,7 @@ import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EventService } from 'jslib-common/abstractions/event.service';
import { ExportService } from 'jslib-common/abstractions/export.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
@ -27,7 +28,8 @@ export class ExportComponent implements OnInit {
constructor(protected cryptoService: CryptoService, protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService, protected exportService: ExportService,
protected eventService: EventService, private policyService: PolicyService, protected win: Window) { }
protected eventService: EventService, private policyService: PolicyService, protected win: Window,
private logService: LogService) { }
async ngOnInit() {
await this.checkExportDisabled();
@ -66,7 +68,9 @@ export class ExportComponent implements OnInit {
this.downloadFile(data);
this.saved();
await this.collectEvent();
} catch { }
} catch (e) {
this.logService.error(e);
}
} else {
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidMasterPassword'));

View File

@ -8,6 +8,7 @@ import {
import { FolderService } from 'jslib-common/abstractions/folder.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { FolderView } from 'jslib-common/models/view/folderView';
@ -25,7 +26,7 @@ export class FolderAddEditComponent implements OnInit {
deletePromise: Promise<any>;
constructor(protected folderService: FolderService, protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService) { }
protected platformUtilsService: PlatformUtilsService, private logService: LogService) { }
async ngOnInit() {
await this.init();
@ -46,7 +47,9 @@ export class FolderAddEditComponent implements OnInit {
this.i18nService.t(this.editMode ? 'editedFolder' : 'addedFolder'));
this.onSavedFolder.emit(this.folder);
return true;
} catch { }
} catch (e) {
this.logService.error(e);
}
return false;
}
@ -64,7 +67,9 @@ export class FolderAddEditComponent implements OnInit {
await this.deletePromise;
this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedFolder'));
this.onDeletedFolder.emit(this.folder);
} catch { }
} catch (e) {
this.logService.error(e);
}
return true;
}

View File

@ -4,6 +4,7 @@ import { PasswordHintRequest } from 'jslib-common/models/request/passwordHintReq
import { ApiService } from 'jslib-common/abstractions/api.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
export class HintComponent {
@ -14,7 +15,8 @@ export class HintComponent {
protected onSuccessfulSubmit: () => void;
constructor(protected router: Router, protected i18nService: I18nService,
protected apiService: ApiService, protected platformUtilsService: PlatformUtilsService) { }
protected apiService: ApiService, protected platformUtilsService: PlatformUtilsService,
private logService: LogService) { }
async submit() {
if (this.email == null || this.email === '') {
@ -37,6 +39,8 @@ export class HintComponent {
} else if (this.router != null) {
this.router.navigate([this.successRoute]);
}
} catch { }
} catch (e) {
this.logService.error(e);
}
}
}

View File

@ -96,7 +96,9 @@ export class IconComponent implements OnChanges {
try {
this.image = this.iconsUrl + '/' + Utils.getHostname(hostnameUri) + '/icon.png';
this.fallbackImage = 'images/fa-globe.png';
} catch (e) { }
} catch (e) {
// Ignore error since the fallback icon will be shown if image is null.
}
}
} else {
this.image = null;

View File

@ -5,6 +5,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@ -47,7 +48,7 @@ export class LockComponent implements OnInit {
protected userService: UserService, protected cryptoService: CryptoService,
protected storageService: StorageService, protected vaultTimeoutService: VaultTimeoutService,
protected environmentService: EnvironmentService, protected stateService: StateService,
protected apiService: ApiService) { }
protected apiService: ApiService, private logService: LogService) { }
async ngOnInit() {
this.pinSet = await this.vaultTimeoutService.isPinLockSet();
@ -129,7 +130,9 @@ export class LockComponent implements OnInit {
const localKeyHash = await this.cryptoService.hashPassword(this.masterPassword, key,
HashPurpose.LocalAuthorization);
await this.cryptoService.setKeyHash(localKeyHash);
} catch { }
} catch (e) {
this.logService.error(e);
}
}
if (passwordValid) {

View File

@ -12,6 +12,7 @@ import { AuthService } from 'jslib-common/abstractions/auth.service';
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@ -49,7 +50,8 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
platformUtilsService: PlatformUtilsService, i18nService: I18nService,
protected stateService: StateService, environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationService,
protected cryptoFunctionService: CryptoFunctionService, private storageService: StorageService) {
protected cryptoFunctionService: CryptoFunctionService, private storageService: StorageService,
protected logService: LogService) {
super(environmentService, i18nService, platformUtilsService);
}
@ -123,7 +125,9 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
this.router.navigate([this.successRoute]);
}
}
} catch { }
} catch (e) {
this.logService.error(e);
}
}
togglePassword() {

View File

@ -2,8 +2,8 @@ import { Directive, OnInit } from '@angular/core';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { TokenService } from 'jslib-common/abstractions/token.service';
import { UserService } from 'jslib-common/abstractions/user.service';
@Directive()
@ -13,7 +13,7 @@ export class PremiumComponent implements OnInit {
refreshPromise: Promise<any>;
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected apiService: ApiService, protected userService: UserService) { }
protected apiService: ApiService, protected userService: UserService, private logService: LogService) { }
async ngOnInit() {
this.isPremium = await this.userService.canAccessPremium();
@ -25,7 +25,9 @@ export class PremiumComponent implements OnInit {
await this.refreshPromise;
this.platformUtilsService.showToast('success', null, this.i18nService.t('refreshComplete'));
this.isPremium = await this.userService.canAccessPremium();
} catch { }
} catch (e) {
this.logService.error(e);
}
}
async purchase() {

View File

@ -10,6 +10,7 @@ import { AuthService } from 'jslib-common/abstractions/auth.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@ -39,7 +40,8 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
i18nService: I18nService, protected cryptoService: CryptoService,
protected apiService: ApiService, protected stateService: StateService,
platformUtilsService: PlatformUtilsService,
protected passwordGenerationService: PasswordGenerationService, environmentService: EnvironmentService) {
protected passwordGenerationService: PasswordGenerationService, environmentService: EnvironmentService,
protected logService: LogService) {
super(environmentService, i18nService, platformUtilsService);
this.showTerms = !platformUtilsService.isSelfHost();
}
@ -158,7 +160,9 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
}
this.platformUtilsService.showToast('success', null, this.i18nService.t('newAccountCreated'));
this.router.navigate([this.successRoute], { queryParams: { email: this.email } });
} catch { }
} catch (e) {
this.logService.error(e);
}
}
togglePassword(confirmField: boolean) {

View File

@ -12,6 +12,7 @@ import { SendType } from 'jslib-common/enums/sendType';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
@ -57,7 +58,8 @@ export class AddEditComponent implements OnInit {
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
protected sendService: SendService, protected userService: UserService,
protected messagingService: MessagingService, protected policyService: PolicyService) {
protected messagingService: MessagingService, protected policyService: PolicyService,
private logService: LogService) {
this.typeOptions = [
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
@ -191,7 +193,9 @@ export class AddEditComponent implements OnInit {
try {
await this.formPromise;
return true;
} catch { }
} catch (e) {
this.logService.error(e);
}
return false;
}
@ -218,7 +222,9 @@ export class AddEditComponent implements OnInit {
await this.load();
this.onDeletedSend.emit(this.send);
return true;
} catch { }
} catch (e) {
this.logService.error(e);
}
return false;
}

View File

@ -4,7 +4,6 @@ import {
OnInit,
} from '@angular/core';
import { OrganizationUserStatusType } from 'jslib-common/enums/organizationUserStatusType';
import { PolicyType } from 'jslib-common/enums/policyType';
import { SendType } from 'jslib-common/enums/sendType';
@ -12,6 +11,7 @@ import { SendView } from 'jslib-common/models/view/sendView';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { SearchService } from 'jslib-common/abstractions/search.service';
@ -48,7 +48,8 @@ export class SendComponent implements OnInit {
constructor(protected sendService: SendService, protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService,
protected ngZone: NgZone, protected searchService: SearchService,
protected policyService: PolicyService, protected userService: UserService) { }
protected policyService: PolicyService, protected userService: UserService,
private logService: LogService) { }
async ngOnInit() {
this.disableSend = await this.policyService.policyAppliesToUser(PolicyType.DisableSend);
@ -129,7 +130,9 @@ export class SendComponent implements OnInit {
this.platformUtilsService.showToast('success', null, this.i18nService.t('removedPassword'));
await this.load();
}
} catch { }
} catch (e) {
this.logService.error(e);
}
this.actionPromise = null;
}
@ -156,7 +159,9 @@ export class SendComponent implements OnInit {
this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedSend'));
await this.refresh();
}
} catch { }
} catch (e) {
this.logService.error(e);
}
this.actionPromise = null;
return true;
}

View File

@ -11,6 +11,7 @@ import { OrganizationUserStatusType } from 'jslib-common/enums/organizationUserS
import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CollectionService } from 'jslib-common/abstractions/collection.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { UserService } from 'jslib-common/abstractions/user.service';
@ -35,7 +36,7 @@ export class ShareComponent implements OnInit {
constructor(protected collectionService: CollectionService, protected platformUtilsService: PlatformUtilsService,
protected i18nService: I18nService, protected userService: UserService,
protected cipherService: CipherService) { }
protected cipherService: CipherService, private logService: LogService) { }
async ngOnInit() {
await this.load();
@ -88,7 +89,9 @@ export class ShareComponent implements OnInit {
});
await this.formPromise;
return true;
} catch { }
} catch (e) {
this.logService.error(e);
}
return false;
}

View File

@ -11,6 +11,7 @@ import { AuthService } from 'jslib-common/abstractions/auth.service';
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
@ -49,7 +50,7 @@ export class SsoComponent {
protected storageService: StorageService, protected stateService: StateService,
protected platformUtilsService: PlatformUtilsService, protected apiService: ApiService,
protected cryptoFunctionService: CryptoFunctionService, protected environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationService) { }
protected passwordGenerationService: PasswordGenerationService, protected logService: LogService) { }
async ngOnInit() {
this.route.queryParams.pipe(first()).subscribe(async qParams => {
@ -180,7 +181,9 @@ export class SsoComponent {
this.router.navigate([this.successRoute]);
}
}
} catch { }
} catch (e) {
this.logService.error(e);
}
this.loggingIn = false;
}

View File

@ -17,6 +17,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service';
import { AuthService } from 'jslib-common/abstractions/auth.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
@ -57,7 +58,8 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
protected i18nService: I18nService, protected apiService: ApiService,
protected platformUtilsService: PlatformUtilsService, protected win: Window,
protected environmentService: EnvironmentService, protected stateService: StateService,
protected storageService: StorageService, protected route: ActivatedRoute) {
protected storageService: StorageService, protected route: ActivatedRoute,
protected logService: LogService) {
this.webAuthnSupported = this.platformUtilsService.supportsWebAuthn(win);
}
@ -216,7 +218,9 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
this.platformUtilsService.showToast('success', null,
this.i18nService.t('verificationCodeEmailSent', this.twoFactorEmail));
}
} catch { }
} catch (e) {
this.logService.error(e);
}
this.emailPromise = null;
}

View File

@ -3,6 +3,7 @@ import { Directive } from '@angular/core';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
@ -31,7 +32,7 @@ export class UpdateTempPasswordComponent extends BaseChangePasswordComponent {
passwordGenerationService: PasswordGenerationService, policyService: PolicyService,
cryptoService: CryptoService, userService: UserService,
messagingService: MessagingService, private apiService: ApiService,
private syncService: SyncService) {
private syncService: SyncService, private logService: LogService) {
super(i18nService, cryptoService, messagingService, userService, passwordGenerationService,
platformUtilsService, policyService);
}
@ -77,7 +78,9 @@ export class UpdateTempPasswordComponent extends BaseChangePasswordComponent {
const newEncKey = await this.cryptoService.remakeEncKey(newKey, userEncKey);
await this.performSubmitActions(newPasswordHash, newKey, newEncKey);
} catch { }
} catch (e) {
this.logService.error(e);
}
}
async performSubmitActions(masterPasswordHash: string, key: SymmetricCryptoKey,
@ -99,6 +102,8 @@ export class UpdateTempPasswordComponent extends BaseChangePasswordComponent {
} else {
this.messagingService.send('logout');
}
} catch { }
} catch (e) {
this.logService.error(e);
}
}
}

View File

@ -21,6 +21,7 @@ import { CipherService } from 'jslib-common/abstractions/cipher.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EventService } from 'jslib-common/abstractions/event.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PasswordRepromptService } from 'jslib-common/abstractions/passwordReprompt.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { TokenService } from 'jslib-common/abstractions/token.service';
@ -31,7 +32,6 @@ import { ErrorResponse } from 'jslib-common/models/response/errorResponse';
import { AttachmentView } from 'jslib-common/models/view/attachmentView';
import { CipherView } from 'jslib-common/models/view/cipherView';
import { FieldView } from 'jslib-common/models/view/fieldView';
import { LoginUriView } from 'jslib-common/models/view/loginUriView';
const BroadcasterSubscriptionId = 'ViewComponent';
@ -69,7 +69,7 @@ export class ViewComponent implements OnDestroy, OnInit {
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
protected changeDetectorRef: ChangeDetectorRef, protected userService: UserService,
protected eventService: EventService, protected apiService: ApiService,
protected passwordRepromptService: PasswordRepromptService) { }
protected passwordRepromptService: PasswordRepromptService, private logService: LogService) { }
ngOnInit() {
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
@ -159,7 +159,9 @@ export class ViewComponent implements OnDestroy, OnInit {
this.platformUtilsService.showToast('success', null,
this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeletedItem' : 'deletedItem'));
this.onDeletedCipher.emit(this.cipher);
} catch { }
} catch (e) {
this.logService.error(e);
}
return true;
}
@ -180,7 +182,9 @@ export class ViewComponent implements OnDestroy, OnInit {
await this.restoreCipher();
this.platformUtilsService.showToast('success', null, this.i18nService.t('restoredItem'));
this.onRestoredCipher.emit(this.cipher);
} catch { }
} catch (e) {
this.logService.error(e);
}
return true;
}

View File

@ -21,7 +21,9 @@ export class PasspackCsvImporter extends BaseImporter implements Importer {
try {
const t = JSON.parse(tagJson);
return this.getValueOrDefault(t.tag);
} catch { }
} catch {
// Ignore error
}
return null;
}).filter((t: string) => !this.isNullOrWhitespace(t)) : null;
@ -72,7 +74,9 @@ export class PasspackCsvImporter extends BaseImporter implements Importer {
fieldsJson.extraFields.length > 0 ? fieldsJson.extraFields.map((fieldJson: string) => {
try {
return JSON.parse(fieldJson);
} catch { }
} catch {
// Ignore error
}
return null;
}) : null;
if (fields != null) {

View File

@ -84,7 +84,9 @@ export class PasswordBossJsonImporter extends BaseImporter implements Importer {
const expDate = new Date(val);
cipher.card.expYear = expDate.getFullYear().toString();
cipher.card.expMonth = (expDate.getMonth() + 1).toString();
} catch { }
} catch {
// Ignore error
}
continue;
} else if (property === 'cardType') {
continue;

View File

@ -43,7 +43,9 @@ export class RememBearCsvImporter extends BaseImporter implements Importer {
cipher.card.expMonth = expMonthNumber.toString();
}
}
} catch { }
} catch {
// Ignore error
}
try {
const expYear = this.getValueOrDefault(value.expiryYear);
if (expYear != null) {
@ -52,7 +54,9 @@ export class RememBearCsvImporter extends BaseImporter implements Importer {
cipher.card.expYear = expYearNumber.toString();
}
}
} catch { }
} catch {
// Ignore error
}
const pin = this.getValueOrDefault(value.pin);
if (pin != null) {

View File

@ -47,7 +47,9 @@ export class TrueKeyCsvImporter extends BaseImporter implements Importer {
const expDate = new Date(value.expiryDate);
cipher.card.expYear = expDate.getFullYear().toString();
cipher.card.expMonth = (expDate.getMonth() + 1).toString();
} catch { }
} catch {
// Ignore error
}
}
} else if (value.kind !== 'login') {
cipher.type = CipherType.SecureNote;

View File

@ -238,7 +238,9 @@ export class Utils {
const urlDomain = tldjs != null && tldjs.getDomain != null ? tldjs.getDomain(url.hostname) : null;
return urlDomain != null ? urlDomain : url.hostname;
} catch (e) { }
} catch (e) {
// Invalid domain, try another approach below.
}
}
try {
@ -367,7 +369,9 @@ export class Utils {
anchor.href = uriString;
return anchor as any;
}
} catch (e) { }
} catch (e) {
// Ignore error
}
return null;
}

View File

@ -27,7 +27,9 @@ export class AttachmentView implements View {
if (this.size != null) {
return parseInt(this.size, null);
}
} catch { }
} catch {
// Invalid file size.
}
return 0;
}
}

View File

@ -23,7 +23,9 @@ export class SendFileView implements View {
if (this.size != null) {
return parseInt(this.size, null);
}
} catch { }
} catch {
// Invalid file size.
}
return 0;
}
}

View File

@ -185,7 +185,9 @@ class Version {
this.year = parts[0];
this.month = parts[1];
this.day = parts[2];
} catch { }
} catch {
// Ignore error
}
}
/**
* Compares two Azure Versions against each other

View File

@ -51,6 +51,7 @@ import { UserService } from '../abstractions/user.service';
import { ConstantsService } from './constants.service';
import { LogService } from '../abstractions/log.service';
import { sequentialize } from '../misc/sequentialize';
import { Utils } from '../misc/utils';
@ -73,7 +74,8 @@ export class CipherService implements CipherServiceAbstraction {
constructor(private cryptoService: CryptoService, private userService: UserService,
private settingsService: SettingsService, private apiService: ApiService,
private fileUploadService: FileUploadService, private storageService: StorageService,
private i18nService: I18nService, private searchService: () => SearchService) {
private i18nService: I18nService, private searchService: () => SearchService,
private logService: LogService) {
}
get decryptedCipherCache() {
@ -423,7 +425,9 @@ export class CipherService implements CipherServiceAbstraction {
if (regex.test(url)) {
return true;
}
} catch { }
} catch (e) {
this.logService.error(e);
}
break;
case UriMatchType.Never:
default:

View File

@ -564,7 +564,9 @@ export class CryptoService implements CryptoServiceAbstraction {
try {
encType = parseInt(headerPieces[0], null);
encPieces = headerPieces[1].split('|');
} catch (e) { }
} catch (e) {
this.logService.error(e);
}
}
switch (encType) {

View File

@ -10,13 +10,15 @@ import { EventService as EventServiceAbstraction } from '../abstractions/event.s
import { StorageService } from '../abstractions/storage.service';
import { UserService } from '../abstractions/user.service';
import { LogService } from '../abstractions/log.service';
import { ConstantsService } from './constants.service';
export class EventService implements EventServiceAbstraction {
private inited = false;
constructor(private storageService: StorageService, private apiService: ApiService,
private userService: UserService, private cipherService: CipherService) { }
private userService: UserService, private cipherService: CipherService,
private logService: LogService) { }
init(checkOnInterval: boolean) {
if (this.inited) {
@ -83,7 +85,9 @@ export class EventService implements EventServiceAbstraction {
try {
await this.apiService.postEventsCollect(request);
this.clearEvents();
} catch { }
} catch (e) {
this.logService.error(e);
}
}
async clearEvents(): Promise<any> {

View File

@ -192,7 +192,9 @@ export class NotificationsService implements NotificationsServiceAbstraction {
if (sync) {
await this.syncService.fullSync(false);
}
} catch { }
} catch (e) {
this.logService.error(e);
}
if (!this.connected) {
this.reconnectTimer = setTimeout(() => this.reconnect(sync), this.random(120000, 300000));

View File

@ -125,7 +125,9 @@ export class SearchService implements SearchServiceAbstraction {
if (isQueryString) {
try {
searchResults = index.search(query.substr(1).trim());
} catch { }
} catch (e) {
this.logService.error(e);
}
} else {
// tslint:disable-next-line
const soWild = lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING;

View File

@ -3,6 +3,7 @@ import { CipherService } from '../abstractions/cipher.service';
import { CollectionService } from '../abstractions/collection.service';
import { CryptoService } from '../abstractions/crypto.service';
import { FolderService } from '../abstractions/folder.service';
import { LogService } from '../abstractions/log.service';
import { MessagingService } from '../abstractions/messaging.service';
import { PolicyService } from '../abstractions/policy.service';
import { SendService } from '../abstractions/send.service';
@ -44,7 +45,8 @@ export class SyncService implements SyncServiceAbstraction {
private cipherService: CipherService, private cryptoService: CryptoService,
private collectionService: CollectionService, private storageService: StorageService,
private messagingService: MessagingService, private policyService: PolicyService,
private sendService: SendService, private logoutCallback: (expired: boolean) => Promise<void>) {
private sendService: SendService, private logService: LogService,
private logoutCallback: (expired: boolean) => Promise<void>) {
}
async getLastSync(): Promise<Date> {
@ -131,7 +133,9 @@ export class SyncService implements SyncServiceAbstraction {
return this.syncCompleted(true);
}
}
} catch { }
} catch (e) {
this.logService.error(e);
}
}
return this.syncCompleted(false);
}
@ -230,7 +234,9 @@ export class SyncService implements SyncServiceAbstraction {
return this.syncCompleted(true);
}
}
} catch { }
} catch (e) {
this.logService.error(e);
}
}
return this.syncCompleted(false);
}

View File

@ -1,6 +1,7 @@
import { ConstantsService } from './constants.service';
import { CryptoFunctionService } from '../abstractions/cryptoFunction.service';
import { LogService } from '../abstractions/log.service';
import { StorageService } from '../abstractions/storage.service';
import { TotpService as TotpServiceAbstraction } from '../abstractions/totp.service';
@ -10,7 +11,8 @@ const B32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
const SteamChars = '23456789BCDFGHJKMNPQRTVWXY';
export class TotpService implements TotpServiceAbstraction {
constructor(private storageService: StorageService, private cryptoFunctionService: CryptoFunctionService) { }
constructor(private storageService: StorageService, private cryptoFunctionService: CryptoFunctionService,
private logService: LogService) { }
async getCode(key: string): Promise<string> {
if (key == null) {
@ -32,7 +34,9 @@ export class TotpService implements TotpServiceAbstraction {
} else if (digitParams > 0) {
digits = digitParams;
}
} catch { }
} catch {
this.logService.error('Invalid digits param.');
}
}
if (params.has('period') && params.get('period') != null) {
try {
@ -40,7 +44,9 @@ export class TotpService implements TotpServiceAbstraction {
if (periodParam > 0) {
period = periodParam;
}
} catch { }
} catch {
this.logService.error('Invalid period param.');
}
}
if (params.has('secret') && params.get('secret') != null) {
keyB32 = params.get('secret');
@ -99,7 +105,9 @@ export class TotpService implements TotpServiceAbstraction {
if (params.has('period') && params.get('period') != null) {
try {
period = parseInt(params.get('period').trim(), null);
} catch { }
} catch {
this.logService.error('Invalid period param.');
}
}
}
return period;

View File

@ -6,6 +6,7 @@ import { WindowMain } from './window.main';
import { BiometricMain } from 'jslib-common/abstractions/biometric.main';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
import { ConstantsService } from 'jslib-common/services/constants.service';
@ -14,7 +15,8 @@ export default class BiometricWindowsMain implements BiometricMain {
private windowsSecurityCredentialsUiModule: any;
constructor(private storageService: StorageService, private i18nservice: I18nService, private windowMain: WindowMain) { }
constructor(private storageService: StorageService, private i18nservice: I18nService, private windowMain: WindowMain,
private logService: LogService) { }
async init() {
this.windowsSecurityCredentialsUiModule = this.getWindowsSecurityCredentialsUiModule();
@ -125,8 +127,9 @@ export default class BiometricWindowsMain implements BiometricMain {
try {
const version = require('os').release();
return Number.parseInt(version.split('.')[0], 10);
} catch {
this.logService.error('Unable to resolve windows major version number');
}
catch { }
return -1;
}
}

View File

@ -1,13 +1,21 @@
import { app, BrowserWindow, screen } from 'electron';
import { ElectronConstants } from './electronConstants';
import {
app,
BrowserWindow,
screen,
} from 'electron';
import * as path from 'path';
import * as url from 'url';
import { isDev, isMacAppStore, isSnapStore } from './utils';
import { LogService } from 'jslib-common/abstractions/log.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
import { ElectronConstants } from './electronConstants';
import {
isDev,
isMacAppStore,
isSnapStore,
} from './utils';
const WindowEventHandlingDelay = 100;
const Keys = {
mainWindowSize: 'mainWindowSize',
@ -21,8 +29,8 @@ export class WindowMain {
private windowStates: { [key: string]: any; } = {};
private enableAlwaysOnTop: boolean = false;
constructor(private storageService: StorageService, private hideTitleBar = false,
private defaultWidth = 950, private defaultHeight = 600,
constructor(private storageService: StorageService, private logService: LogService,
private hideTitleBar = false, private defaultWidth = 950, private defaultHeight = 600,
private argvCallback: (argv: string[]) => void = null,
private createWindowCallback: (win: BrowserWindow) => void) { }
@ -224,7 +232,9 @@ export class WindowMain {
}
await this.storageService.save(configKey, this.windowStates[configKey]);
} catch (e) { }
} catch (e) {
this.logService.error(e);
}
}
private async getWindowState(configKey: string, defaultWidth: number, defaultHeight: number) {

View File

@ -468,7 +468,9 @@ export class LoginCommand {
});
foundPort = true;
break;
} catch { }
} catch {
// Ignore error since we run the same command up to 5 times.
}
}
if (!foundPort) {
reject();

View File

@ -4,6 +4,7 @@ import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { FileUploadService } from 'jslib-common/abstractions/fileUpload.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { SearchService } from 'jslib-common/abstractions/search.service';
import { SettingsService } from 'jslib-common/abstractions/settings.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
@ -28,6 +29,7 @@ describe('Cipher Service', () => {
let storageService: SubstituteOf<StorageService>;
let i18nService: SubstituteOf<I18nService>;
let searchService: SubstituteOf<SearchService>;
let logService: SubstituteOf<LogService>;
let cipherService: CipherService;
@ -40,12 +42,13 @@ describe('Cipher Service', () => {
storageService = Substitute.for<StorageService>();
i18nService = Substitute.for<I18nService>();
searchService = Substitute.for<SearchService>();
logService = Substitute.for<LogService>();
cryptoService.encryptToBytes(Arg.any(), Arg.any()).resolves(ENCRYPTED_BYTES);
cryptoService.encrypt(Arg.any(), Arg.any()).resolves(new EncString(ENCRYPTED_TEXT));
cipherService = new CipherService(cryptoService, userService, settingsService, apiService, fileUploadService,
storageService, i18nService, () => searchService);
storageService, i18nService, () => searchService, logService);
});
it('attachments upload encrypted file contents', async () => {

View File

@ -35,7 +35,7 @@
]
}
],
"no-empty": [ true, "allow-empty-catch" ],
"no-empty": [ true ],
"object-literal-sort-keys": false,
"object-literal-shorthand": [ true, "never" ],
"ordered-imports": true,