Version parsing failure in unikraft.go discards underlying error detail

Open Beginner friendly
#891 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
backend

Research direction

Open pkg/unikontainers/unikernels/unikraft.go and start at the version.NewVersion error branch. Preserve the existing fallback behavior while checking that the returned error retains both the sentinel and parsing detail. Run the relevant Go tests, if available, and confirm callers can still identify ErrVersionParsing.

Written by the indexing model from the issue text.

Description

dev enhancement

In pkg/unikontainers/unikernels/unikraft.go:

unikernelVersion, err := version.NewVersion(u.Version)
if err != nil {
    setCurrentArgs()
    return ErrVersionParsing
}

Right now, when the version string fails to parse, urunc throws away the actual parsing error and just returns a generic ErrVersionParsing. So you can see that something failed, but not why, was the string empty, malformed, using the wrong separator, etc.
There's already a fallback (setCurrentArgs()) that kicks in, so it doesn't break anything but it makes it harder than necessary to identify when the version string is invalid.
hashicorp/go-version returns ordinary errors rather than typed or sentinel errors, so errors.Is/errors.As cannot be used to distinguish the failure reason. Wrapping the original error preserves both the existing sentinel and the parsing details:

-    return ErrVersionParsing
+    return fmt.Errorf("%w: %w", ErrVersionParsing, err)

This keeps errors.Is(err, ErrVersionParsing) working for callers while exposing the underlying parse error in the returned message. The fallback behavior remains unchanged because setCurrentArgs() is still executed.

Related: #884

Dominant language
Go
Stars
298
Forks
202
Avg merge
2d 18h
Merged PRs (30d)
28

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from urunc-dev/urunc

All issues in urunc-dev/urunc

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.