Skip to content

Commit

Permalink
fix(manager): unify logging (#22398)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
  • Loading branch information
viceice and secustor committed May 25, 2023
1 parent e066924 commit 497d4c1
Show file tree
Hide file tree
Showing 61 changed files with 321 additions and 236 deletions.
8 changes: 4 additions & 4 deletions lib/modules/manager/ansible-galaxy/extract.ts
Expand Up @@ -24,16 +24,16 @@ export function getSliceEndNumber(

export function extractPackageFile(
content: string,
fileName: string
packageFile: string
): PackageFileContent | null {
logger.trace('ansible-galaxy.extractPackageFile()');
logger.trace(`ansible-galaxy.extractPackageFile(${packageFile})`);
const galaxyFileNameRegEx = regEx(/galaxy\.ya?ml$/);
const deps: PackageDependency[] = [];
const lines = content.split(newlineRegex);

try {
// if this is a galaxy.yml file we have to interpret the dependencies differently
if (galaxyFileNameRegEx.exec(fileName)) {
if (galaxyFileNameRegEx.exec(packageFile)) {
const galaxyDeps = extractCollectionsMetaDataFile(lines);
deps.push(...galaxyDeps);
} else {
Expand Down Expand Up @@ -87,7 +87,7 @@ export function extractPackageFile(
}
return { deps };
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'Error extracting ansible-galaxy deps');
logger.debug({ err, packageFile }, 'Error extracting ansible-galaxy deps');
return null;
}
}
4 changes: 2 additions & 2 deletions lib/modules/manager/ansible/extract.ts
Expand Up @@ -10,10 +10,10 @@ import type {

export function extractPackageFile(
content: string,
_filename: string,
packageFile: string,
config: ExtractConfig
): PackageFileContent | null {
logger.trace('ansible.extractPackageFile()');
logger.trace(`ansible.extractPackageFile(${packageFile})`);
let deps: PackageDependency[] = [];
const re = regEx(/^\s*image:\s*'?"?([^\s'"]+)'?"?\s*$/);
for (const line of content.split(newlineRegex)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/argocd/extract.ts
Expand Up @@ -20,7 +20,7 @@ import { fileTestRegex } from './util';

export function extractPackageFile(
content: string,
fileName: string,
packageFile: string,
_config?: ExtractConfig
): PackageFileContent | null {
// check for argo reference. API version for the kind attribute is used
Expand All @@ -32,7 +32,7 @@ export function extractPackageFile(
try {
definitions = loadAll(content) as ApplicationDefinition[];
} catch (err) {
logger.debug({ err, fileName }, 'Failed to parse ArgoCD definition.');
logger.debug({ err, packageFile }, 'Failed to parse ArgoCD definition.');
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/asdf/extract.ts
Expand Up @@ -6,7 +6,7 @@ import type { PackageDependency, PackageFileContent } from '../types';
import { upgradeableTooling } from './upgradeable-tooling';

export function extractPackageFile(content: string): PackageFileContent | null {
logger.trace('asdf.extractPackageFile()');
logger.trace(`asdf.extractPackageFile()`);

const regex = regEx(
/^(?<toolName>([\w_-]+)) (?<version>[^\s#]+)(?: [^\s#]+)* *(?: #(?<comment>.*))?$/gm
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/manager/azure-pipelines/extract.ts
Expand Up @@ -101,13 +101,13 @@ export function extractAzurePipelinesTasks(

export function parseAzurePipelines(
content: string,
filename: string
packageFile: string
): AzurePipelines | null {
let pkg: AzurePipelines | null = null;
try {
pkg = load(content, { json: true }) as AzurePipelines;
} catch (err) /* istanbul ignore next */ {
logger.info({ filename, err }, 'Error parsing azure-pipelines content');
logger.debug({ packageFile, err }, 'Error parsing azure-pipelines content');
return null;
}

Expand All @@ -116,12 +116,12 @@ export function parseAzurePipelines(

export function extractPackageFile(
content: string,
filename: string
packageFile: string
): PackageFileContent | null {
logger.trace(`azurePipelines.extractPackageFile(${filename})`);
logger.trace(`azurePipelines.extractPackageFile(${packageFile})`);
const deps: PackageDependency[] = [];

const pkg = parseAzurePipelines(content, filename);
const pkg = parseAzurePipelines(content, packageFile);
if (!pkg) {
return null;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/manager/batect/extract.ts
Expand Up @@ -119,9 +119,9 @@ function extractReferencedConfigFiles(

export function extractPackageFile(
content: string,
fileName: string
packageFile: string
): ExtractionResult | null {
logger.trace(`batect.extractPackageFile() fileName: ${fileName}`);
logger.trace(`batect.extractPackageFile(${packageFile})`);

try {
const config = loadConfig(content);
Expand All @@ -132,13 +132,13 @@ export function extractPackageFile(

const referencedConfigFiles = extractReferencedConfigFiles(
config,
fileName
packageFile
);

return { deps, referencedConfigFiles };
} catch (err) {
logger.warn(
{ err, fileName },
logger.debug(
{ err, packageFile },
'Extracting dependencies from Batect configuration file failed'
);

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/bazel-module/extract.ts
Expand Up @@ -6,15 +6,15 @@ import { parse } from './parser';

export function extractPackageFile(
content: string,
filename: string
packageFile: string
): PackageFileContent | null {
try {
const records = parse(content);
return LooseArray(ToBazelDep)
.transform((deps) => (deps.length ? { deps } : null))
.parse(records);
} catch (err) {
logger.debug({ err, filename }, 'Failed to parse bazel module file.');
logger.debug({ err, packageFile }, 'Failed to parse bazel module file.');
return null;
}
}
4 changes: 2 additions & 2 deletions lib/modules/manager/bicep/extract.ts
Expand Up @@ -12,8 +12,8 @@ const RESOURCE_REGEX = regEx(

export function extractPackageFile(
content: string,
packageFile: string,
config: ExtractConfig
_packageFile: string,
_config: ExtractConfig
): Promise<PackageFileContent | null> {
const deps: PackageDependency[] = [];

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/bitbucket-pipelines/extract.ts
Expand Up @@ -12,7 +12,7 @@ import {

export function extractPackageFile(
content: string,
filename: string
packageFile: string
): PackageFileContent | null {
const deps: PackageDependency[] = [];

Expand Down Expand Up @@ -60,7 +60,7 @@ export function extractPackageFile(
}
} catch (err) /* istanbul ignore next */ {
logger.debug(
{ err, filename },
{ err, packageFile },
'Error extracting Bitbucket Pipes dependencies'
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/modules/manager/buildkite/extract.ts
Expand Up @@ -5,7 +5,10 @@ import { GithubTagsDatasource } from '../../datasource/github-tags';
import { isVersion } from '../../versioning/semver';
import type { PackageDependency, PackageFileContent } from '../types';

export function extractPackageFile(content: string): PackageFileContent | null {
export function extractPackageFile(
content: string,
packageFile?: string
): PackageFileContent | null {
const deps: PackageDependency[] = [];
try {
const lines = content.split(newlineRegex);
Expand Down Expand Up @@ -70,7 +73,7 @@ export function extractPackageFile(content: string): PackageFileContent | null {
}
}
} catch (err) /* istanbul ignore next */ {
logger.warn({ err }, 'Error extracting BuildKite plugins');
logger.debug({ err, packageFile }, 'Error extracting BuildKite plugins');
}

if (!deps.length) {
Expand Down
24 changes: 12 additions & 12 deletions lib/modules/manager/bundler/extract.ts
Expand Up @@ -14,7 +14,7 @@ function formatContent(input: string): string {

export async function extractPackageFile(
content: string,
fileName?: string
packageFile?: string
): Promise<PackageFileContent | null> {
const res: PackageFileContent = {
registryUrls: [],
Expand Down Expand Up @@ -75,8 +75,8 @@ export async function extractPackageFile(
groupLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(groupLine)) {
logger.warn(
{ content, fileName, type: 'groupLine' },
logger.debug(
{ content, packageFile, type: 'groupLine' },
'Bundler parsing error'
);
groupLine = 'end';
Expand Down Expand Up @@ -113,8 +113,8 @@ export async function extractPackageFile(
sourceLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(sourceLine)) {
logger.warn(
{ content, fileName, type: 'sourceLine' },
logger.debug(
{ content, packageFile, type: 'sourceLine' },
'Bundler parsing error'
);
sourceLine = 'end';
Expand Down Expand Up @@ -148,8 +148,8 @@ export async function extractPackageFile(
platformsLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(platformsLine)) {
logger.warn(
{ content, fileName, type: 'platformsLine' },
logger.debug(
{ content, packageFile, type: 'platformsLine' },
'Bundler parsing error'
);
platformsLine = 'end';
Expand Down Expand Up @@ -181,8 +181,8 @@ export async function extractPackageFile(
ifLine = lines[lineNumber];
// istanbul ignore if
if (!is.string(ifLine)) {
logger.warn(
{ content, fileName, type: 'ifLine' },
logger.debug(
{ content, packageFile, type: 'ifLine' },
'Bundler parsing error'
);
ifLine = 'end';
Expand All @@ -209,11 +209,11 @@ export async function extractPackageFile(
return null;
}

if (fileName) {
const gemfileLock = fileName + '.lock';
if (packageFile) {
const gemfileLock = `${packageFile}.lock`;
const lockContent = await readLocalFile(gemfileLock, 'utf8');
if (lockContent) {
logger.debug(`Found Gemfile.lock file packageFile: ${fileName}`);
logger.debug(`Found Gemfile.lock file packageFile: ${packageFile}`);
res.lockFiles = [gemfileLock];
const lockedEntries = extractLockFileEntries(lockContent);
for (const dep of res.deps) {
Expand Down
11 changes: 7 additions & 4 deletions lib/modules/manager/cargo/extract.ts
Expand Up @@ -150,10 +150,10 @@ function extractCargoRegistries(config: CargoConfig | null): CargoRegistries {

export async function extractPackageFile(
content: string,
fileName: string,
packageFile: string,
_config?: ExtractConfig
): Promise<PackageFileContent | null> {
logger.trace(`cargo.extractPackageFile(${fileName})`);
logger.trace(`cargo.extractPackageFile(${packageFile})`);

const cargoConfig = await readCargoConfig();
const cargoRegistries = extractCargoRegistries(cargoConfig);
Expand All @@ -162,7 +162,7 @@ export async function extractPackageFile(
try {
cargoManifest = parse(content);
} catch (err) {
logger.debug({ err }, 'Error parsing Cargo.toml file');
logger.debug({ err, packageFile }, 'Error parsing Cargo.toml file');
return null;
}
/*
Expand Down Expand Up @@ -227,7 +227,10 @@ export async function extractPackageFile(
if (!deps.length) {
return null;
}
const lockFileName = await findLocalSiblingOrParent(fileName, 'Cargo.lock');
const lockFileName = await findLocalSiblingOrParent(
packageFile,
'Cargo.lock'
);
const res: PackageFileContent = { deps };
// istanbul ignore if
if (lockFileName) {
Expand Down
7 changes: 5 additions & 2 deletions lib/modules/manager/circleci/extract.ts
Expand Up @@ -5,7 +5,10 @@ import * as npmVersioning from '../../versioning/npm';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types';

export function extractPackageFile(content: string): PackageFileContent | null {
export function extractPackageFile(
content: string,
packageFile?: string
): PackageFileContent | null {
const deps: PackageDependency[] = [];
try {
const lines = content.split(newlineRegex);
Expand Down Expand Up @@ -71,7 +74,7 @@ export function extractPackageFile(content: string): PackageFileContent | null {
}
}
} catch (err) /* istanbul ignore next */ {
logger.warn({ err }, 'Error extracting circleci images');
logger.debug({ err, packageFile }, 'Error extracting circleci images');
}
if (!deps.length) {
return null;
Expand Down
11 changes: 7 additions & 4 deletions lib/modules/manager/cloudbuild/extract.ts
Expand Up @@ -4,7 +4,10 @@ import { logger } from '../../../logger';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types';

export function extractPackageFile(content: string): PackageFileContent | null {
export function extractPackageFile(
content: string,
packageFile?: string
): PackageFileContent | null {
const deps: PackageDependency[] = [];
try {
// TODO: fix types
Expand All @@ -29,12 +32,12 @@ export function extractPackageFile(content: string): PackageFileContent | null {
} catch (err) /* istanbul ignore next */ {
if (err.stack?.startsWith('YAMLException:')) {
logger.debug(
{ err },
{ err, packageFile },
'YAML exception extracting Docker images from a Cloud Build configuration file.'
);
} else {
logger.warn(
{ err },
logger.debug(
{ err, packageFile },
'Error extracting Docker images from a Cloud Build configuration file.'
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/manager/cocoapods/extract.ts
Expand Up @@ -82,9 +82,9 @@ export function gitDep(parsedLine: ParsedLine): PackageDependency | null {

export async function extractPackageFile(
content: string,
fileName: string
packageFile: string
): Promise<PackageFileContent | null> {
logger.trace('cocoapods.extractPackageFile()');
logger.trace(`cocoapods.extractPackageFile(${packageFile})`);
const deps: PackageDependency[] = [];
const lines: string[] = content.split(newlineRegex);

Expand Down Expand Up @@ -146,7 +146,7 @@ export async function extractPackageFile(
}
}
const res: PackageFileContent = { deps };
const lockFile = getSiblingFileName(fileName, 'Podfile.lock');
const lockFile = getSiblingFileName(packageFile, 'Podfile.lock');
// istanbul ignore if
if (await localPathExists(lockFile)) {
res.lockFiles = [lockFile];
Expand Down
9 changes: 6 additions & 3 deletions lib/modules/manager/composer/extract.ts
Expand Up @@ -4,11 +4,14 @@ import { ComposerExtract } from './schema';

export async function extractPackageFile(
content: string,
fileName: string
packageFile: string
): Promise<PackageFileContent | null> {
const res = await ComposerExtract.safeParseAsync({ content, fileName });
const res = await ComposerExtract.safeParseAsync({
content,
fileName: packageFile,
});
if (!res.success) {
logger.debug({ fileName, err: res.error }, 'Composer: extract failed');
logger.debug({ packageFile, err: res.error }, 'Composer: extract failed');
return null;
}
return res.data;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/cpanfile/extract.ts
Expand Up @@ -3,7 +3,7 @@ import { parse } from './parser';

export function extractPackageFile(
content: string,
packageFile?: string
_packageFile?: string
): PackageFileContent | null {
const result = parse(content);
if (!result?.deps.length) {
Expand Down

0 comments on commit 497d4c1

Please sign in to comment.