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(forest-cloud): show stack trace for business errors during bootstrap #1254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/forest-cloud/src/services/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ export default async function bootstrap(
const datasources = await httpServer.getDatasources();

await updateTypings(datasources, paths);
} catch (error) {
} catch (e) {
const error = e as Error;
const potentialErrorMessage = await tryToClearBootstrap(paths);
throw new BusinessError(`Bootstrap failed: ${error.message}.${potentialErrorMessage || ''}`);

throw new BusinessError(
`Bootstrap failed: ${error.message}. ${potentialErrorMessage || ''}${error.stack}`,
);
}
}
16 changes: 7 additions & 9 deletions packages/forest-cloud/test/services/bootstrap.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,27 @@ describe('bootstrap', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
const httpServer = new HttpServer('', '', '');
const path = new BootstrapPathManager('', '');
HttpServer.downloadCloudCustomizerTemplate = jest
.fn()
.mockRejectedValue(new Error('Failed'));
const error = new Error('Failed');
HttpServer.downloadCloudCustomizerTemplate = jest.fn().mockRejectedValue(error);

await expect(
bootstrap(
{ FOREST_ENV_SECRET: 'abc' } as unknown as EnvironmentVariables,
httpServer,
path,
),
).rejects.toEqual(new BusinessError('Bootstrap failed: Failed.'));
).rejects.toEqual(new BusinessError(`Bootstrap failed: Failed. ${error.stack}`));
});

describe('If there is an error when trying to clear the bootstrap', () => {
it('should notify the client to clear the "forest-cloud" folder', async () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
const httpServer = new HttpServer('', '', '');
const path = new BootstrapPathManager('', '');
HttpServer.downloadCloudCustomizerTemplate = jest
.fn()
.mockRejectedValue(new Error('Failed'));
const error = new Error('Failed');
HttpServer.downloadCloudCustomizerTemplate = jest.fn().mockRejectedValue(error);
// throw error when trying to clear
jest.spyOn(fsP, 'rm').mockRejectedValue(new Error('Failed'));
jest.spyOn(fsP, 'rm').mockRejectedValue(new Error('Cannot remove file'));

await expect(
bootstrap(
Expand All @@ -104,7 +102,7 @@ describe('bootstrap', () => {
),
).rejects.toEqual(
new BusinessError(
'Bootstrap failed: Failed.\nPlease remove "forest-cloud" folder and re-run bootstrap command.',
`Bootstrap failed: Failed. \nPlease remove "forest-cloud" folder and re-run bootstrap command.${error.stack}`,
),
);
});
Expand Down
Loading