Skip to content

Commit

Permalink
fix(datasource): better DatasourceError handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 14, 2020
1 parent 292993f commit 12166f5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
1 change: 0 additions & 1 deletion lib/datasource/index.ts
Expand Up @@ -91,7 +91,6 @@ export async function getPkgReleases(
});
} catch (e) /* istanbul ignore next */ {
if (e instanceof DatasourceError) {
logger.warn({ datasource, lookupName, err: e.err }, 'Datasource failure');
e.datasource = datasource;
e.lookupName = lookupName;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/manager/gradle/index.ts
Expand Up @@ -3,7 +3,6 @@ import upath from 'upath';

import { exec, ExecOptions } from '../../util/exec';
import { logger } from '../../logger';
import { DATASOURCE_FAILURE } from '../../constants/error-messages';
import { VERSION_SCHEME_MAVEN } from '../../constants/version-schemes';

import {
Expand All @@ -26,6 +25,7 @@ import { platform } from '../../platform';
import { LANGUAGE_JAVA } from '../../constants/languages';
import { DATASOURCE_MAVEN } from '../../constants/data-binary-source';
import { BinarySource } from '../../util/exec/common';
import { DatasourceError } from '../../datasource';

export const GRADLE_DEPENDENCY_REPORT_OPTIONS =
'--init-script renovate-plugin.gradle renovate';
Expand Down Expand Up @@ -91,7 +91,9 @@ async function executeGradle(
}
logger.warn({ err, cmd }, 'Gradle run failed');
logger.info('Aborting Renovate due to Gradle lookup errors');
throw new Error(DATASOURCE_FAILURE);
const error = new DatasourceError(err);
error.datasource = 'gradle';
throw error;
}
logger.debug(stdout + stderr);
logger.info('Gradle report complete');
Expand Down
35 changes: 26 additions & 9 deletions lib/manager/npm/post-update/index.ts
Expand Up @@ -12,10 +12,8 @@ import * as hostRules from '../../../util/host-rules';
import { getChildProcessEnv } from '../../../util/exec/env';
import { PostUpdateConfig, PackageFile, Upgrade } from '../../common';
import { platform } from '../../../platform';
import {
SYSTEM_INSUFFICIENT_DISK_SPACE,
DATASOURCE_FAILURE,
} from '../../../constants/error-messages';
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
import { DatasourceError } from '../../../datasource/common';

// Strips empty values, deduplicates, and returns the directories from filenames
// istanbul ignore next
Expand Down Expand Up @@ -386,7 +384,10 @@ export async function getAdditionalFiles(
{ dependency: upgrade.depName, type: 'npm' },
'lock file failed for the dependency being updated - skipping branch creation'
);
throw new Error(DATASOURCE_FAILURE);
const err = new Error(
'lock file failed for the dependency being updated - skipping branch creation'
);
throw new DatasourceError(err);
}
}
}
Expand Down Expand Up @@ -438,7 +439,11 @@ export async function getAdditionalFiles(
{ dependency: upgrade.depName, type: 'yarn' },
'lock file failed for the dependency being updated - skipping branch creation'
);
throw new Error(DATASOURCE_FAILURE);
throw new DatasourceError(
new Error(
'lock file failed for the dependency being updated - skipping branch creation'
)
);
}
/* eslint-enable no-useless-escape */
}
Expand Down Expand Up @@ -524,7 +529,11 @@ export async function getAdditionalFiles(
{ dependency: upgrade.depName, type: 'pnpm' },
'lock file failed for the dependency being updated - skipping branch creation'
);
throw new Error(DATASOURCE_FAILURE);
throw new DatasourceError(
Error(
'lock file failed for the dependency being updated - skipping branch creation'
)
);
}
}
}
Expand Down Expand Up @@ -593,7 +602,11 @@ export async function getAdditionalFiles(
{ dependency: upgrade.depName, type: 'yarn' },
'lock file failed for the dependency being updated - skipping branch creation'
);
throw new Error(DATASOURCE_FAILURE);
throw new DatasourceError(
Error(
'lock file failed for the dependency being updated - skipping branch creation'
)
);
}
/* eslint-enable no-useless-escape */
if (
Expand All @@ -605,7 +618,11 @@ export async function getAdditionalFiles(
{ dependency: upgrade.depName, type: 'npm' },
'lock file failed for the dependency being updated - skipping branch creation'
);
throw new Error(DATASOURCE_FAILURE);
throw new DatasourceError(
Error(
'lock file failed for the dependency being updated - skipping branch creation'
)
);
}
}
artifactErrors.push({
Expand Down
8 changes: 3 additions & 5 deletions lib/manager/npm/post-update/yarn.ts
Expand Up @@ -4,11 +4,9 @@ import { getInstalledPath } from 'get-installed-path';
import { exec } from '../../../util/exec';
import { logger } from '../../../logger';
import { PostUpdateConfig, Upgrade } from '../../common';
import {
SYSTEM_INSUFFICIENT_DISK_SPACE,
DATASOURCE_FAILURE,
} from '../../../constants/error-messages';
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
import { BinarySource } from '../../../util/exec/common';
import { DatasourceError } from '../../../datasource';

export interface GenerateLockFileResult {
error?: boolean;
Expand Down Expand Up @@ -179,7 +177,7 @@ export async function generateLockFile(
err.stderr.includes('getaddrinfo ENOTFOUND registry.yarnpkg.com') ||
err.stderr.includes('getaddrinfo ENOTFOUND registry.npmjs.org')
) {
throw new Error(DATASOURCE_FAILURE);
throw new DatasourceError(err);
}
}
return { error: true, stderr: err.stderr };
Expand Down
10 changes: 10 additions & 0 deletions lib/workers/repository/error.ts
Expand Up @@ -29,6 +29,7 @@ import {
SYSTEM_INSUFFICIENT_DISK_SPACE,
UNKNOWN_ERROR,
} from '../../constants/error-messages';
import { DatasourceError } from '../../datasource/common';

export default async function handleError(
config: RenovateConfig,
Expand Down Expand Up @@ -105,6 +106,15 @@ export default async function handleError(
await raiseConfigWarningIssue(config, err);
return err.message;
}
if (err instanceof DatasourceError) {
logger.warn(
{ datasource: err.datasource, lookupName: err.lookupName, err: err.err },
'Datasource failure'
);
logger.info('Registry error - skipping');
delete config.branchList; // eslint-disable-line no-param-reassign
return err.message;
}
if (err.message === DATASOURCE_FAILURE) {
logger.info('Registry error - skipping');
delete config.branchList; // eslint-disable-line no-param-reassign
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/init/config.ts
Expand Up @@ -14,7 +14,7 @@ import { configFileNames } from '../../../config/app-strings';
import { platform } from '../../../platform';
import {
CONFIG_VALIDATION,
DATASOURCE_FAILURE,
PLATFORM_FAILURE,
} from '../../../constants/error-messages';

// Check for repository config
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function mergeRenovateConfig(
// istanbul ignore if
if (renovateConfig === null) {
logger.warn('Fetching renovate config returns null');
throw new Error(DATASOURCE_FAILURE);
throw new Error(PLATFORM_FAILURE);
}
// istanbul ignore if
if (!renovateConfig.length) {
Expand Down
5 changes: 5 additions & 0 deletions test/workers/repository/error.spec.ts
Expand Up @@ -27,6 +27,7 @@ import {
UNKNOWN_ERROR,
} from '../../../lib/constants/error-messages';
import { RenovateConfig, getConfig } from '../../util';
import { DatasourceError } from '../../../lib/datasource/common';

jest.mock('../../../lib/workers/repository/error-config');

Expand Down Expand Up @@ -70,6 +71,10 @@ describe('workers/repository/error', () => {
expect(res).toEqual(err);
});
});
it(`handles DatasourceError`, async () => {
const res = await handleError(config, new DatasourceError(new Error()));
expect(res).toEqual(DATASOURCE_FAILURE);
});
it('rewrites git 5xx error', async () => {
const gitError = new Error(
"fatal: unable to access 'https://**redacted**@gitlab.com/learnox/learnox.git/': The requested URL returned error: 500\n"
Expand Down

0 comments on commit 12166f5

Please sign in to comment.