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

refactor(logger): remove templating from WARN log messages #33488

Merged
merged 4 commits into from
Jan 14, 2025
Merged
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
4 changes: 2 additions & 2 deletions lib/modules/datasource/bitrise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export class BitriseDatasource extends Datasource {
}
if (body.encoding !== 'base64') {
logger.warn(
{ data: body, url: stepUrl },
`Got unexpected encoding for Bitrise step location '${body.encoding}'`,
{ encoding: body.encoding, data: body, url: stepUrl },
`Got unexpected encoding for Bitrise step location`,
);
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/deb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ export class DebDatasource extends Datasource {
return response.statusCode !== 304;
} catch (error) {
logger.warn(
`Could not determine if ${packageUrl} is modified since ${lastDownloadTimestamp.toUTCString()}: ${error.message}`,
{ packageUrl, lastDownloadTimestamp, errorMessage: error.message },
'Could not determine if package file is modified since last download',
);
return true; // Assume it needs to be downloaded if check fails
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/deno/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ describe('modules/datasource/deno/index', () => {
expect(logger.logger.warn).toHaveBeenCalledWith(
expect.objectContaining({
err: expect.any(ZodError),
version: '0.161.0',
}),
`Deno: failed to get version details for 0.161.0`,
'Deno: failed to get version details',
);
});

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class DenoDatasource extends Datasource {
url,
DenoAPIModuleVersionResponse.catch(({ error: err }) => {
logger.warn(
{ err },
`Deno: failed to get version details for ${version}`,
{ err, version },
'Deno: failed to get version details',
);
return { version };
}),
Expand Down
12 changes: 6 additions & 6 deletions lib/modules/datasource/galaxy-collection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class GalaxyCollectionDatasource extends Datasource {
.getJsonSafe(baseUrl, GalaxyV3)
.onError((err) => {
logger.warn(
{ datasource: this.id, packageName, err },
`Error fetching ${baseUrl}`,
{ url: baseUrl, datasource: this.id, packageName, err },
'Error fetching from url',
);
})
.unwrap();
Expand All @@ -80,8 +80,8 @@ export class GalaxyCollectionDatasource extends Datasource {
.getJsonSafe(versionsUrl, GalaxyV3Versions)
.onError((err) => {
logger.warn(
{ datasource: this.id, packageName, err },
`Error fetching ${versionsUrl}`,
{ url: versionsUrl, datasource: this.id, packageName, err },
'Error fetching from url',
);
})
.unwrap();
Expand Down Expand Up @@ -136,8 +136,8 @@ export class GalaxyCollectionDatasource extends Datasource {
.getJsonSafe(detailedVersionUrl, GalaxyV3DetailedVersion)
.onError((err) => {
logger.warn(
{ datasource: this.id, packageName, err },
`Error fetching ${versionsUrl}`,
{ url: versionsUrl, datasource: this.id, packageName, err },
'Error fetching from url',
);
})
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/galaxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class GalaxyDatasource extends Datasource {
if (!body.results.length) {
logger.warn(
{ dependency: packageName, userName },
`Multiple results from galaxy for ${packageName}, none match`,
`No matching result from galaxy for package`,
);
return null;
}
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/datasource/hex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export class HexDatasource extends Datasource {
const { val: result, err } = await this.http
.getJsonSafe(hexUrl, HexRelease)
.onError((err) => {
logger.warn({ datasource: 'hex', packageName, err }, `Error fetching ${hexUrl}`); // prettier-ignore
logger.warn(
{ url: hexUrl, datasource: 'hex', packageName, err },
'Error fetching from url',
);
})
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async function fetchReleases(
let { registryUrls } = config;
// istanbul ignore if: need test
if (!datasourceName || getDatasourceFor(datasourceName) === undefined) {
logger.warn('Unknown datasource: ' + datasourceName);
logger.warn({ datasource: datasourceName }, 'Unknown datasource');
return null;
}
if (datasourceName === 'npm') {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/npm/npmrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function envReplace(value: any, env = process.env): any {

return value.replace(ENV_EXPR, (match, _esc, envVarName) => {
if (env[envVarName] === undefined) {
logger.warn('Failed to replace env in config: ' + match);
logger.warn({ match }, 'Failed to replace env in config');
throw new Error('env-replace');
}
return env[envVarName];
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/cargo/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ async function updateArtifactsImpl(
// If there is a dependency without a locked version then log a warning
// and perform a regular workspace lockfile update.
logger.warn(
`Missing locked version for dependency \`${missingDep.depName}\``,
{ dependency: missingDep.depName },
'Missing locked version for dependency',
);
await cargoUpdate(
packageFileName,
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/cargo/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function resolveRegistryIndex(
`Replacing index of cargo registry ${registryName} with ${replacementName}`,
);
if (originalNames.has(replacementName)) {
logger.warn(`${registryName} cargo registry resolves to itself`);
logger.warn({ registryName }, 'cargo registry resolves to itself');
return null;
}
return resolveRegistryIndex(
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/npm/update/package-version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function bumpPackageVersion(
parsedContent.optionalDependencies?.[mirrorPackage] ??
parsedContent.peerDependencies?.[mirrorPackage];
if (!newPjVersion) {
logger.warn('bumpVersion mirror package not found: ' + mirrorPackage);
logger.warn({ mirrorPackage }, 'bumpVersion mirror package not found');
return { bumpedContent };
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/pip-compile/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ export function extractPythonVersion(
const match = pythonVersionRegex.exec(content);
if (match?.groups === undefined) {
logger.warn(
`pip-compile: failed to extract Python version from header in ${fileName} ${content}`,
{ fileName, content },
'pip-compile: failed to extract Python version from header in file',
);
return undefined;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/manager/pip-compile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ describe('modules/manager/pip-compile/extract', () => {
const packageFiles = await extractAllPackageFiles({}, lockFiles);
expect(packageFiles?.map((p) => p.lockFiles)).toEqual([['2.txt']]);
expect(logger.warn).toHaveBeenCalledWith(
'pip-compile: 1.in references reqs-no-headers.txt which does not appear to be a requirements file managed by pip-compile',
{ packageFile: '1.in', requirementsFile: 'reqs-no-headers.txt' },
'pip-compile: Package file references a file which does not appear to be a requirements file managed by pip-compile',
);
});

Expand All @@ -494,7 +495,8 @@ describe('modules/manager/pip-compile/extract', () => {
const packageFiles = await extractAllPackageFiles({}, lockFiles);
expect(packageFiles?.map((p) => p.lockFiles)).toEqual([['2.txt']]);
expect(logger.warn).toHaveBeenCalledWith(
'pip-compile: 1.in references unmanaged-file.txt which does not appear to be a requirements file managed by pip-compile',
{ packageFile: '1.in', requirementsFile: 'unmanaged-file.txt' },
'pip-compile: Package file references a file which does not appear to be a requirements file managed by pip-compile',
);
});

Expand Down
8 changes: 6 additions & 2 deletions lib/modules/manager/pip-compile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export async function extractAllPackageFiles(
compileArgs = extractHeaderCommand(fileContent, fileMatch);
compileDir = inferCommandExecDir(fileMatch, compileArgs.outputFile);
} catch (error) {
logger.warn({ fileMatch }, `pip-compile: ${error.message}`);
logger.warn(
{ fileMatch, errorMessage: error.message },
'pip-compile error',
);
continue;
}
lockFileArgs.set(fileMatch, compileArgs);
Expand Down Expand Up @@ -212,7 +215,8 @@ export async function extractAllPackageFiles(
}
if (!sourceFiles) {
logger.warn(
`pip-compile: ${packageFile.packageFile} references ${reqFile} which does not appear to be a requirements file managed by pip-compile`,
{ packageFile: packageFile.packageFile, requirementsFile: reqFile },
'pip-compile: Package file references a file which does not appear to be a requirements file managed by pip-compile',
);
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/pipenv/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export function addExtraEnvVariable(
extraEnv[environmentVariableName] !== environmentValue
) {
logger.warn(
`Possible misconfiguration, ${environmentVariableName} is already set to a different value`,
{ envVar: environmentVariableName },
'Possible misconfiguration, environment variable already set to a different value',
);
}
extraEnv[environmentVariableName] = environmentValue;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/azure/azure-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export async function getFile(
const result = WrappedExceptionSchema.safeParse(fileContent);
if (result.success) {
if (result.data.typeKey === 'GitItemNotFoundException') {
logger.warn(`Unable to find file ${filePath}`);
logger.warn({ filePath }, 'Unable to find file');
return null;
}
if (result.data.typeKey === 'GitUnresolvableToCommitException') {
logger.warn(`Unable to find branch ${branchName}`);
logger.warn({ branchName }, 'Unable to find branch');
return null;
}
}
Expand Down
12 changes: 7 additions & 5 deletions lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,13 @@ export async function mergePr({

if (!isClosed) {
logger.warn(
{ pullRequestId, status: pr.status },
`Expected PR to have status ${
PullRequestStatus[PullRequestStatus.Completed]
// TODO #22198
}. However, it is ${PullRequestStatus[pr.status!]}.`,
{
pullRequestId,
status: pr.status,
expectedPRStatus: PullRequestStatus[PullRequestStatus.Completed],
actualPRStatus: PullRequestStatus[pr.status!],
},
'Expected PR to have completed status. However, the PR has a different status',
);
}
return true;
Expand Down
5 changes: 2 additions & 3 deletions lib/modules/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ export async function getRawFile(
if (isLastPage) {
return lines.map(({ text }) => text).join('\n');
}
const msg = `The file is too big (${size}B)`;
logger.warn({ size }, msg);
throw new Error(msg);
logger.warn({ size }, 'The file is too big');
throw new Error(`The file is too big (${size}B)`);
}

export async function getJsonFile(
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/platform/gerrit/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class GerritScm extends DefaultGitScm {
return !mergeInfo.mergeable;
} else {
logger.warn(
`There is no open change with branch=${branch} and baseBranch=${baseBranch}`,
{ branch, baseBranch },
'There is no open change with this branch',
);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/platform/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ const platform: Platform = {
// would cause a HTTP 409 conflict error, which we hereby gracefully handle.
if (err.statusCode === 409) {
logger.warn(
`Attempting to gracefully recover from 409 Conflict response in createPr(${title}, ${sourceBranch})`,
{ prTitle: title, sourceBranch },
'Attempting to gracefully recover from 409 Conflict response in createPr()',
);

// Refresh cached PR list and search for pull request with matching information
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/versioning/pep440/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function getNewValue({
if (!ranges.length) {
// an empty string is an allowed value for PEP440 range
// it means get any version
logger.warn('Empty currentValue: ' + currentValue);
logger.warn({ currentValue }, 'Empty currentValue');
return currentValue;
}
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion lib/util/cache/repository/impl/s3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ describe('util/cache/repository/impl/s3', () => {
s3Mock.on(GetObjectCommand, getObjectCommandInput).resolvesOnce({});
await expect(s3Cache.read()).resolves.toBeNull();
expect(logger.warn).toHaveBeenCalledWith(
"RepoCacheS3.read() - failure - expecting Readable return type got 'undefined' type instead",
{ returnType: 'undefined' },
'RepoCacheS3.read() - failure - got unexpected return type',
);
});

Expand Down
3 changes: 2 additions & 1 deletion lib/util/cache/repository/impl/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class RepoCacheS3 extends RepoCacheBase {
return await streamToString(res);
}
logger.warn(
`RepoCacheS3.read() - failure - expecting Readable return type got '${typeof res}' type instead`,
{ returnType: typeof res },
'RepoCacheS3.read() - failure - got unexpected return type',
);
} catch (err) {
// https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
Expand Down
11 changes: 6 additions & 5 deletions lib/util/git/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export function getGitAuthenticatedEnvironmentVariables(
): NodeJS.ProcessEnv {
if (!token && !(username && password)) {
logger.warn(
// TODO: types (#22198)
`Could not create environment variable for ${matchHost!} as neither token or username and password was set`,
{ host: matchHost },
`Could not create environment variable for host as neither token or username and password was set`,
);
return { ...environmentVariables };
}
Expand All @@ -41,9 +41,10 @@ export function getGitAuthenticatedEnvironmentVariables(
gitConfigCount = parseInt(gitConfigCountEnvVariable, 10);
if (Number.isNaN(gitConfigCount)) {
logger.warn(
`Found GIT_CONFIG_COUNT env variable, but couldn't parse the value to an integer: ${String(
process.env.GIT_CONFIG_COUNT,
)}. Ignoring it.`,
{
GIT_CONFIG_COUNT: process.env.GIT_CONFIG_COUNT,
},
`Found GIT_CONFIG_COUNT env variable, but couldn't parse the value to an integer. Ignoring it.`,
);
gitConfigCount = 0;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ export async function cloneSubmodules(
git.submoduleUpdate(['--init', '--recursive', submodule]),
);
} catch (err) {
logger.warn(
{ err },
`Unable to initialise git submodule at ${submodule}`,
);
logger.warn({ err, submodule }, `Unable to initialise git submodule`);
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions lib/workers/global/config/parse/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export async function migrateAndValidateConfig(
const { isMigrated, migratedConfig } = migrateConfig(config);
if (isMigrated) {
logger.warn(
{ originalConfig: config, migratedConfig },
`${configType} needs migrating`,
{ configType, originalConfig: config, migratedConfig },
'Config needs migrating',
);
}
const massagedConfig = massageConfig(migratedConfig);
Expand All @@ -25,13 +25,10 @@ export async function migrateAndValidateConfig(
const { warnings, errors } = await validateConfig('global', massagedConfig);

if (warnings.length) {
logger.warn(
{ warnings },
`Config validation warnings found in ${configType}`,
);
logger.warn({ configType, warnings }, 'Config validation warnings found');
}
if (errors.length) {
logger.warn({ errors }, `Config validation errors found in ${configType}`);
logger.warn({ configType, errors }, 'Config validation errors found');
}

return massagedConfig;
Expand Down
6 changes: 4 additions & 2 deletions lib/workers/repository/init/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ describe('workers/repository/init/index', () => {
);
await initRepo({});
expect(logger.logger.warn).toHaveBeenCalledWith(
"Configuration option 'filterUnavailableUsers' is not supported on the current platform 'undefined'.",
{ platform: undefined },
"Configuration option 'filterUnavailableUsers' is not supported on the current platform.",
);
expect(logger.logger.warn).toHaveBeenCalledWith(
"Configuration option 'expandCodeOwnersGroups' is not supported on the current platform 'undefined'.",
{ platform: undefined },
"Configuration option 'expandCodeOwnersGroups' is not supported on the current platform.",
);
});
});
Expand Down
6 changes: 4 additions & 2 deletions lib/workers/repository/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ function warnOnUnsupportedOptions(config: RenovateConfig): void {
// TODO: types (#22198)
const platform = GlobalConfig.get('platform')!;
logger.warn(
`Configuration option 'filterUnavailableUsers' is not supported on the current platform '${platform}'.`,
{ platform },
`Configuration option 'filterUnavailableUsers' is not supported on the current platform.`,
);
}

if (config.expandCodeOwnersGroups && !platform.expandGroupMembers) {
// TODO: types (#22198)
const platform = GlobalConfig.get('platform')!;
logger.warn(
`Configuration option 'expandCodeOwnersGroups' is not supported on the current platform '${platform}'.`,
{ platform },
`Configuration option 'expandCodeOwnersGroups' is not supported on the current platform.`,
);
}
}
Expand Down
Loading
Loading