Skip to content

Commit

Permalink
fix(#9618): don't crash api on startup if form is broken (#9641)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan authored Nov 14, 2024
1 parent b85e1e5 commit a9aea1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,27 @@ process
await migrations.run();
logger.info('Database migrations completed successfully');

startupLog.start('forms');
logger.info('Generating manifest');
await manifest.generate();
logger.info('Manifest generated successfully');

logger.info('Generating service worker');
await generateServiceWorker.run(true);
logger.info('Service worker generated successfully');
} catch (err) {
logger.error('Fatal error initialising API');
logger.error('%o', err);
process.exit(1);
}

try {
startupLog.start('forms');
logger.info('Updating xforms…');
await generateXform.updateAll();
logger.info('xforms updated successfully');

} catch (err) {
logger.error('Fatal error initialising API');
logger.error('Error initialising API');
logger.error('%o', err);
process.exit(1);
}

startupLog.complete();
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/api/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,28 @@ describe('server', () => {
});

});

describe('api startup', () => {
it('should start up with broken forms', async () => {
const waitForLogs = await utils.waitForApiLogs(/Failed to update xform/);

const formName = 'broken';
const formDoc = {
_id: `form:${formName}`,
title: formName,
type: 'form',
_attachments: {
xml: {
content_type: 'application/octet-stream',
data: btoa('this is totally not an xml'),
},
},
};
await utils.db.put(formDoc); // don't use utils.saveDoc because that actually waits for good forms
await waitForLogs.promise;

await utils.stopApi();
await utils.startApi();
});
});
});

0 comments on commit a9aea1e

Please sign in to comment.