Skip to content

Conversation

@j-luong
Copy link
Collaborator

@j-luong j-luong commented Dec 2, 2025

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • Commit messages
    are release-note ready, emphasizing
    what was changed, not how.
  • Includes detailed description of changes
  • Contains risk assessment (Low)
  • Highlights breaking API changes (if applicable)
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___)
  • Includes product update to be announced in the next stable release notes

What does this PR do?

This PR fixes an issue where an unsupported glibc version will result in a generic error catalog error and an exit code 1 for some Snyk commands.

We will not exit code 2 and provide a more useful RequirementsNotMet error catalog error.

Low risk as it fixes an already existing exit condition by changing exit codes and messaging.

Where should the reviewer start?

How should this be manually tested?

What's the product update that needs to be communicated to CLI users?

Fixed an issue where the CLI would exit with the wrong exit code when certain runtime requirements are not met. The CLI will now exit correctly with an appropriate error message.

@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch 2 times, most recently from 4027467 to 7546c5a Compare December 3, 2025 16:23
// ValidateGlibcVersion checks if the glibc version is supported and returns an Error Catalog error if it is not.
// This check only applies to glibc-based Linux systems (amd64, arm64).
// Optionally accepts a custom GlibcVersion, mainly for testing.
func ValidateGlibcVersion(opt ...GlibcVersion) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Move the glibc validation logic and constants close to the legacycli workflow, since the requirement comes from there. The logic to return the glibc version can be here.

}

// detectGlibcVersion attempts to detect the glibc version on Linux systems
func detectGlibcVersion() (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: I think we do have plenty of examples on the structure of the ldd output, maybe we can improve the implementation by using this knowledge and adding tests for the different cases? Adding tests for the extraction logic would require it to be callable with a string though. But this would actually implement IOSP. So probably worth it.

@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch 6 times, most recently from 0b9dd34 to 20b3987 Compare December 9, 2025 19:59
@j-luong j-luong marked this pull request as ready for review December 10, 2025 09:05
@j-luong j-luong requested review from a team as code owners December 10, 2025 09:05
}

version, err := versionFn()
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question: Do we really want to fail the validation, if there was an error in the version function? I would think this could be to strict and fail more often then we want to. IMO it would be better to not fail the validation if any intermediate step fails.

}

res, err := utils.SemverCompare(version, minVersion)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same question about failing as above

// parseSemver("2.27") // returns []int{2, 27}
// parseSemver("2.31") // returns []int{2, 31}
// parseSemver("2.35") // returns []int{2, 35}
func parseSemver(v string) ([]int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: since semver is actually a bit more advanced than just 1.2.3 should we maybe use a library to do proper parsing and comparison?

Copy link
Collaborator

Choose a reason for hiding this comment

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

depending on the decision, if we keep our own implementation, let's add some tests for parseSemver() and SemverCompare().

Copy link
Collaborator Author

@j-luong j-luong Dec 12, 2025

Choose a reason for hiding this comment

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

Will use golang.org/x/mod/semver package instead, which performs the same functionality and should be more robust

"sync"
)

const (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Move this to legacycli, as it is defined by the nodejs runtime which is part of the legacycli workflow.

// SemverCompare("2.27", "2.31") // returns -1
// SemverCompare("2.31", "2.31") // returns 0
// SemverCompare("2.35", "2.31") // returns 1
func SemverCompare(v1 string, v2 string) (int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question: It took me a while to fully understand the behaviour and the usage, so I'm wondering if a simpler function like SemverGreaterEquals() bool or SemverLessThan() bool is easier to understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will use golang.org/x/mod/semver package for semver comparison instead

@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch 3 times, most recently from d135904 to 8be1f1b Compare December 17, 2025 12:08
}

var minVersion string
switch runtime.GOARCH {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: If the architecture becomes a parameter to the function, tests can actually be written without depending on the platform architecture they are executed on.

// ValidateGlibcVersion checks if the glibc version is supported and returns an Error Catalog error if it is not.
// This check only applies to glibc-based Linux systems (amd64, arm64).
// Optionally accepts a custom GlibcVersion, mainly for testing.
func ValidateGlibcVersion(debugLogger *zerolog.Logger, opt ...utils.GlibcVersion) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: just use regular parameter for utils.GlibcVersion, debuglogger, runtime, goos, goarch and skip the optional parameter.

@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch from 8be1f1b to 342a4ec Compare December 17, 2025 17:14
expectedSnykErrCode string
}

tests := []test{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Let's also add some edge cases (like windows ...) to ensure they are correctly covered.

@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch 3 times, most recently from 20f379e to f721656 Compare December 18, 2025 16:05
@j-luong j-luong enabled auto-merge December 18, 2025 16:07
v2 = "v" + v2
}

return semver.Compare(v1, v2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Let's be a bit paranoid and check if both versions are actually valid using isValid()

Copy link
Collaborator

Choose a reason for hiding this comment

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

just because the doc of Compare() says the following

An invalid semantic version string is considered less than a valid one. All invalid semantic version strings compare equal to each other.

@j-luong j-luong disabled auto-merge December 18, 2025 16:10
@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch from f721656 to d9eab3d Compare December 18, 2025 16:13
@j-luong j-luong force-pushed the fix/cli-1230_glibcChecker branch from d9eab3d to 66fbb50 Compare December 18, 2025 16:19
@j-luong j-luong enabled auto-merge December 18, 2025 16:21
@github-actions
Copy link
Contributor

Warnings
⚠️ There are multiple commits on your branch, please squash them locally before merging!

Generated by 🚫 dangerJS against ca11db1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants