Skip to content

Commit

Permalink
feat: SeededPodInitializer log exceptions as warning instead of crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiyo-no-sake authored and joachimvh committed Feb 3, 2023
1 parent 5acddcb commit 2efc141
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/init/SeededPodInitializer.ts
@@ -1,6 +1,7 @@
import { readJson } from 'fs-extra';
import type { RegistrationManager } from '../identity/interaction/email-password/util/RegistrationManager';
import { getLoggerFor } from '../logging/LogUtil';
import { createErrorMessage } from '../util/errors/ErrorUtil';
import { Initializer } from './Initializer';

/**
Expand Down Expand Up @@ -42,10 +43,15 @@ export class SeededPodInitializer extends Initializer {
this.logger.debug(`Validated input: ${JSON.stringify(validated)}`);

// Register and/or create a pod as requested. Potentially does nothing if all booleans are false.
await this.registrationManager.register(validated, true);
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
count += 1;
try {
await this.registrationManager.register(validated, true);
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
count += 1;
} catch (error: unknown) {
this.logger.warn(`Error while initializing seeded pod: ${createErrorMessage(error)})}`);
}
}

this.logger.info(`Initialized ${count} seeded pods.`);
}
}
7 changes: 7 additions & 0 deletions test/unit/init/SeededPodInitializer.test.ts
Expand Up @@ -45,4 +45,11 @@ describe('A SeededPodInitializer', (): void => {
expect(registrationManager.validateInput).toHaveBeenCalledTimes(2);
expect(registrationManager.register).toHaveBeenCalledTimes(2);
});

it('does not throw exceptions when a seeded pod already exists.', async(): Promise<void> => {
registrationManager.register = jest.fn().mockRejectedValueOnce(new Error('Pod already exists'));
await new SeededPodInitializer(registrationManager, configFilePath).handle();
expect(registrationManager.validateInput).toHaveBeenCalledTimes(2);
expect(registrationManager.register).toHaveBeenCalledTimes(2);
});
});

0 comments on commit 2efc141

Please sign in to comment.