Skip to content
Snippets Groups Projects
Commit cc2288ef authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix: add try-catch to getFileList (#975)

parent 3841f29b
Branches
No related tags found
No related merge requests found
......@@ -233,6 +233,7 @@ async function getFileList(branchName) {
if (config.fileList) {
return config.fileList;
}
try {
const res = await get(
`repos/${config.repoName}/git/trees/${branchName}?recursive=true`
);
......@@ -246,6 +247,12 @@ async function getFileList(branchName) {
.filter(item => item.type === 'blob')
.map(item => item.path)
.sort();
} catch (err) {
// TODO: change this from warn to info once we know exactly why it happens
logger.warn({ repository: config.repoName }, 'Error retrieving git tree');
config.fileList = [];
}
return config.fileList;
}
......
......@@ -128,6 +128,7 @@ async function getFileList(branchName) {
if (config.fileList) {
return config.fileList;
}
try {
const res = await get(
`projects/${config.repoName}/repository/tree?ref=${branchName}&recursive=true&per_page=100`,
{ paginate: true }
......@@ -136,6 +137,10 @@ async function getFileList(branchName) {
.filter(item => item.type === 'blob')
.map(item => item.path)
.sort();
} catch (err) {
logger.warn('Error retrieving git tree');
config.fileList = [];
}
return config.fileList;
}
......
......@@ -469,6 +469,16 @@ describe('api/github', () => {
expect(get.mock.calls).toMatchSnapshot();
});
});
describe('getFileList', () => {
it('returns empty array if error', async () => {
await initRepo('some/repo', 'token');
get.mockImplementationOnce(() => {
throw new Error('some error');
});
const files = await github.findFilePaths('someething');
expect(files).toEqual([]);
});
});
describe('findFilePaths(fileName)', () => {
it('warns if truncated result', async () => {
await initRepo('some/repo', 'token');
......
......@@ -191,6 +191,14 @@ describe('api/gitlab', () => {
});
});
describe('findFilePaths(fileName)', () => {
it('returns empty array if error', async () => {
await initRepo('some/repo', 'token');
get.mockImplementationOnce(() => {
throw new Error('some error');
});
const files = await gitlab.findFilePaths('someething');
expect(files).toEqual([]);
});
it('warns if truncated result', async () => {
await initRepo('some/repo', 'token');
get.mockImplementationOnce(() => ({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment