Skip to content
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
13 changes: 5 additions & 8 deletions lib/analyzer/image-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ async function pullWithDockerBinary(
password: string | undefined,
platform: string | undefined,
): Promise<boolean> {
let pullAndSaveSuccessful = false;
try {
if (username || password) {
debug(
Expand All @@ -57,13 +56,12 @@ async function pullWithDockerBinary(
}
await docker.pullCli(targetImage, { platform });
await docker.save(targetImage, saveLocation);
return (pullAndSaveSuccessful = true);
return true;
} catch (err) {
debug(`couldn't pull ${targetImage} using docker binary: ${err.message}`);

handleDockerPullError(err.stderr, platform);

return pullAndSaveSuccessful;
return false;
}
}

Expand All @@ -81,10 +79,9 @@ function handleDockerPullError(err: string, platform?: string) {
"manifest unknown",
];
if (unknownManifestConditions.some((value) => err.includes(value))) {
if (platform) {
throw new Error(`The image does not exist for ${platform}`);
}
throw new Error(`The image does not exist for the current platform`);
throw new Error(
`The image does not exist for ${platform ?? "the current platform"}`,
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Error Message Regression with Nullish Coalescing

The change to use the nullish coalescing operator (??) alters the error message when the platform parameter is an empty string (""). Previously, the error was "The image does not exist for the current platform". Now, it is "The image does not exist for ", which is less clear and unexpected given platform is typed as string | undefined.

Fix in Cursor Fix in Web

}

if (err.includes("invalid reference format")) {
Expand Down
21 changes: 8 additions & 13 deletions lib/inputs/file-pattern/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@ import { ExtractAction, ExtractedLayers } from "../../extractor/types";
import { streamToString } from "../../stream-utils";
import { ManifestFile } from "../../types";

/**
* Return false if any exclusion pattern matches,
* return true if any inclusion pattern matches
*/
function generatePathMatcher(
globsInclude: string[],
globsExclude: string[],
): (filePath: string) => boolean {
return (filePath: string): boolean => {
let exclude = false;
for (const g of globsExclude) {
if (!exclude && minimatch(filePath, g)) {
exclude = true;
}
}
if (!exclude) {
for (const g of globsInclude) {
if (minimatch(filePath, g)) {
return true;
}
}
if (globsExclude.some((glob) => minimatch(filePath, glob))) {
return false;
}
return false;

return globsInclude.some((glob) => minimatch(filePath, glob));
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/python-parser/requirements-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ export function getRequirements(fileContent: string): PythonRequirement[] {

function parseLine(line: string): PythonRequirement | null {
line = line.trim();
if (line.length === 0) {
// there's no point in calling the regex if the line is a comment
if (line.length === 0 || line.startsWith("#")) {
return null;
}
const parsedLine = VERSION_PARSE_REGEX.exec(line);
if (!parsedLine?.groups) {
return null;
}
const { name, extras, specifier, version } = parsedLine.groups;
const correctedSpecifier = specifierValidRange(specifier, version);
return {
name: name.toLowerCase(),
specifier: correctedSpecifier,
specifier: specifierValidRange(specifier, version),
version,
extras: parseExtraNames(extras),
} as PythonRequirement;
Expand Down