question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Semver.toString() adds additional information to the version string

See original GitHub issue

new Semver("1.0.0", SemverType.NPM).toString() returns Semver(1.0.0).

We are using this in another project to parse two versions and determine whether they are compatible. If they are not we throw an exception with a message that is built this way:

MessageFormat.format("Versions \"{0}\" and \"{1}\" are incompatible", version1, version2);

This results in the following message:

Versions "Semver(1.0.0)" and "Semver(2.0.0)" are incompatible.

while we would like to have this message:

Versions "1.0.0" and "2.0.0" are incompatible.

To achive this we had to modify our code in the following way:

MessageFormat.format("Versions \"{0}\" and \"{1}\" are incompatible", version1.getOriginalValue(), version2.getOriginalValue());

The first approach is cleaner and therefore we would prefer it if toString() did not add “Semver()” to the returned value, if possible.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vdurmontcommented, Dec 4, 2015

I get your problem and I think you’re right. Initially, I wanted a clear distinction between the 3 methods:

Semver s = new Semver(" 1.2.3-beta ");
System.out.println(s); // Prints: "Semver(1.2.3-beta)"
System.out.println(s.getOriginalValue()); // Prints: " 1.2.3-beta "
System.out.println(s.getValue()); // Prints: "1.2.3-beta"

(note the spaces)

I guess we could make toString return the current getValue. I don’t want to return the original value because I want a “normalized” toString method.

Does that make sense? Would that be ok?

0reactions
sschuberthcommented, Jul 9, 2017

I guess we could make toString return the current getValue.

Any update on that? The code change should be trivial…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: Adding System.SemanticVersion · Issue #19317
I have use cases from parsing package versions to determining which version of Elasticsearch a client is connected to. There's a broad spectrum ......
Read more >
SemanticVersion Class (System.Management.Automation)
An implementation of semantic versioning (https://semver.org) that can be converted to/from Version. When converting to Version, a PSNoteProperty is added ...
Read more >
Semantic Versioning 2.0.0 | Semantic Versioning
Given a version number MAJOR.MINOR.PATCH, increment the: MAJOR version when you make incompatible API changes; MINOR version when you add functionality in a ......
Read more >
Comparing version number strings (major, minor, revision ...
Here's one suggestion: static int[] getVersionNumbers(String ver) { Matcher m = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(beta(\\d*))?
Read more >
Template Function List
A list of template functions available in Helm.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found