pants icon indicating copy to clipboard operation
pants copied to clipboard

go mod init results in "ValueError: invalid literal for int() with base 10: '21.0'"

Open leedenison opened this issue 2 years ago • 6 comments

Describe the bug Using go mod init to initialise a default go.mod generates a file containing: go 1.21.0

This causes go run for the related go binary target to fail with:

ValueError: invalid literal for int() with base 10: '21.0'

Editing go.mod to instead contain go 1.21 causes the build to succeed.

Pants version 2.16.0

OS Linux

Additional info Stack trace:

lee@lepton:~/[...]/service$ pants --print-stacktrace run src/[...]/service:bin
14:51:33.10 [INFO] Initializing scheduler...
14:51:38.89 [INFO] Scheduler initialized.
14:51:39.52 [ERROR] 1 Exception encountered:

Engine traceback:
  in select
    ..
  in pants.core.goals.run.run
    `run` goal

Traceback (most recent call last):
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 623, in native_engine_generator_send
    res = rule.send(arg) if err is None else rule.throw(throw or err)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/core/goals/run.py", line 292, in run
    request = await (
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 118, in __await__
    result = yield self
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 623, in native_engine_generator_send
    res = rule.send(arg) if err is None else rule.throw(throw or err)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/backend/go/goals/run_binary.py", line 15, in create_go_binary_run_request
    binary = await Get(BuiltPackage, PackageFieldSet, field_set)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 118, in __await__
    result = yield self
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 623, in native_engine_generator_send
    res = rule.send(arg) if err is None else rule.throw(throw or err)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/backend/go/goals/package_binary.py", line 100, in package_go_binary
    built_package = await Get(
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 118, in __await__
    result = yield self
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 623, in native_engine_generator_send
    res = rule.send(arg) if err is None else rule.throw(throw or err)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/backend/go/util_rules/build_pkg.py", line 716, in build_go_package
    if go_root.is_compatible_version(go_version):
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/backend/go/util_rules/goroot.py", line 40, in is_compatible_version
    return compatible_go_version(compiler_version=self.version, target_version=version)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/backend/go/util_rules/go_bootstrap.py", line 140, in compatible_go_version
    return parse(target_version) <= parse(compiler_version)
  File "/home/lee/.cache/nce/[...]/bindings/venvs/2.16.0/lib/python3.9/site-packages/pants/backend/go/util_rules/go_bootstrap.py", line 138, in parse
    return int(major), int(minor)
ValueError: invalid literal for int() with base 10: '21.0'

leedenison avatar Aug 14 '23 14:08 leedenison

Welcome to the Pantsbuild Community. This looks like your first issue here. Thanks for taking the time to write it.

If you haven't already, feel free to come say hi on Slack.

If you have questions, or just want to surface this issue, check out the #development channel. (If you want to check it out without logging in, check out our Linen mirror)

Thanks again, and we look forward to your next Issue/PR :smile:!

WorkerPants avatar Aug 14 '23 14:08 WorkerPants

Any update on this? Seems like a small fix to just ignore the last patch version for now. Can help to pick this up if no one else is doing this.

johansja avatar Mar 14 '24 09:03 johansja

Contributions are always welcome, so feel free to do so @johansja :)

tgolsson avatar Mar 14 '24 10:03 tgolsson

Submitted a pull request here: https://github.com/pantsbuild/pants/pull/20677

johansja avatar Mar 15 '24 07:03 johansja

I think #20677 indicated it was fixing this issue.

I note that that PR has Pants ignores the patch version, is that potentially a recipe for confusion in future? (Where something might require version 1.2.3, and Pants decides that Go 1.2.1 is ok 💥) I know nothing about Go, just wanting to confirm there's no potential time-bomb.

huonw avatar May 09 '24 10:05 huonw

It is quite rare for this part of Go to be restricted to a particular patch version. And new features wont' be introduced in patch version. Can read this for more info. https://go.dev/ref/mod#go-mod-file-go

Indeed it is only a quick fix. If we aim for completeness, we can aim to support patch version verification as well.

johansja avatar May 10 '24 01:05 johansja