Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Multiple labeled tags leads to NumberFormatException during project load #192

Open
fcv opened this issue Sep 30, 2021 · 3 comments
Open

Comments

@fcv
Copy link

fcv commented Sep 30, 2021

In case of multiple tags on HEAD, if any of them is labeled, then a NumberFormatException is thrown and project can't be loaded.

For example, let's say I have v1.0.0 and v1.0.1-alpha, an exception like the one below is thrown:

java.lang.NumberFormatException: For input string: "1-alpha"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.base/java.lang.Integer.parseInt(Integer.java:652)
	at java.base/java.lang.Integer.valueOf(Integer.java:983)
	at versionsort.VersionHelper.compare(VersionHelper.java:32)
	at com.typesafe.sbt.SbtGit$git$.$anonfun$releaseVersion$3(SbtGit.scala:266)
	at com.typesafe.sbt.SbtGit$git$.$anonfun$releaseVersion$3$adapted(SbtGit.scala:266)
	at scala.math.Ordering$$anon$4.compare(Ordering.scala:234)
	at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.base/java.util.TimSort.sort(TimSort.java:220)
	at java.base/java.util.Arrays.sort(Arrays.java:1441)
	at scala.collection.SeqLike.sorted(SeqLike.scala:659)
	at scala.collection.SeqLike.sorted$(SeqLike.scala:647)
	at scala.collection.AbstractSeq.sorted(Seq.scala:45)
	at scala.collection.SeqLike.sortWith(SeqLike.scala:612)
	at scala.collection.SeqLike.sortWith$(SeqLike.scala:612)
	at scala.collection.AbstractSeq.sortWith(Seq.scala:45)
	at com.typesafe.sbt.SbtGit$git$.releaseVersion(SbtGit.scala:266)
	at com.typesafe.sbt.SbtGit$.$anonfun$versionWithGit$8(SbtGit.scala:196)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:228)
	at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:170)
	at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:87)
	at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:99)
	at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:94)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
[error] java.lang.NumberFormatException: For input string: "1-alpha"
[error] Use 'last' for the full log.

From what I could check it's related to #162 and the fact that versionsort.VersionHelper expects tags to strictly follow a pattern like \d(\.\d)+ failing otherwise.

Affected version: 1.0.1.

In order to support projects using different tagging patterns would it be possible to make the tag ordering configurable or disable it altogether?

Ps.: I would be willing to contribute.

fcv added a commit to fcv/sbt-git that referenced this issue Dec 6, 2021
fcv added a commit to fcv/sbt-git that referenced this issue Dec 6, 2021
fcv added a commit to fcv/sbt-git that referenced this issue Dec 8, 2021
@spangaer
Copy link

spangaer commented Jul 5, 2022

For the next person that hits this.

It looks to be caused by
https://github.com/sbt/sbt-git/blob/v1.0.2/src/main/scala/com/typesafe/sbt/SbtGit.scala#L266

Which looks to be fixed in the 2.0 version
https://github.com/sbt/sbt-git/blob/main/src/main/scala/com/github/sbt/git/GitPlugin.scala#L303

You can get around it in 1.x by relying on git describe versioning and disabling tag versioning by filtering all tags:

git.useGitDescribe := true
git.gitDescribePatterns := Seq("v[0-9]*")
git.gitTagToVersionNumber := { _: String => None }

@spangaer
Copy link

spangaer commented Sep 6, 2022

Dang. I just now discovered that that omits dropping the v-prefix. So it looks 2.0 is a better way forward.

@spangaer
Copy link

spangaer commented Dec 6, 2022

Ok, I found a similar but not the same problem that bubbles up in a multi tag context.

https://github.com/sbt/sbt-git/blob/v2.0.0/src/main/scala/com/github/sbt/git/GitPlugin.scala#L275

If this needs to sort x.y.z-alpha-1, you also get a number format exception.

As with the previous problem, it only surfaces if you have multiple results that need sorting.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants