Skip to content

cmd/create, pkg/utils: Add spinner helpers and distro image matching#1781

Open
DaliborKr wants to merge 3 commits into
containers:mainfrom
DaliborKr:pr02-spinner-utils
Open

cmd/create, pkg/utils: Add spinner helpers and distro image matching#1781
DaliborKr wants to merge 3 commits into
containers:mainfrom
DaliborKr:pr02-spinner-utils

Conversation

@DaliborKr
Copy link
Copy Markdown
Collaborator

This is PR 2/10 in a series adding cross-architecture container support using QEMU and binfmt_misc.

Depends on: #1780 (pkg/shell: Preserve error types in shell command execution)
Please review #1780 first. The new commits in this PR are:

  • cmd/create: Extract spinner setup into helper functions
  • pkg/utils: Add IsSupportedDistroImage for image to supported distro matching

Summary

  • Introcude startSpinner() and stopSpinner() helper functions covering the inline spinner code in createContainer() and pullImage(), reducing repetition and making future spinner usage simpler
  • Add IsSupportedDistroImage() to the utils package for checking whether an image reference matches any natively supported distribution's base image name (see Toolbx supported distros)

The existing RunContextWithExitCode() wraps all errors from
exec.Command in generic "failed to invoke" messages, which prevents
callers from distinguishing between actual error types.

Add RunContextWithExitCode2() and RunWithExitCode2() that return
errors with their original types intact, including for ExitError.
This allows callers to use errors.Is() and errors.As() to handle
specific failure modes. For example, detecting a missing skopeo binary
(exec.ErrNotFound) or an ENOEXEC error from inside non native
containers, when an emulator is not set correctly.

These new functions are meant to replace its original versions in the
future.

containers#1780

Signed-off-by: Dalibor Kricka <dalidalk@seznam.cz>
@DaliborKr DaliborKr requested a review from debarshiray as a code owner April 23, 2026 04:53
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the spinner logic into reusable helper functions, introduces new shell execution utilities with enhanced logging, and adds a helper to identify supported distro images. A potential panic was identified in the spinner implementation where a nil pointer could be dereferenced if the stop helper is not used consistently; a refactor to ensure a valid spinner instance is always returned was suggested.

Comment thread src/cmd/create.go
Comment on lines +958 to +966
func startSpinner(message string) *spinner.Spinner {
if logLevel := logrus.GetLevel(); logLevel < logrus.DebugLevel {
s := spinner.New(spinner.CharSets[9], 500*time.Millisecond, spinner.WithWriterFile(os.Stdout))
s.Prefix = message
s.Start()
return s
}
return nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The current implementation of startSpinner returns nil when the log level is Debug or higher. However, there is a direct call to s.Stop() at line 497 (visible in the full file but outside this diff hunk) that does not check for nil. This will cause a panic when running with verbose logging (e.g., toolbox create --verbose).

To fix this, you should either use the stopSpinner(s) helper at line 497 or refactor startSpinner to always return a spinner instance that is only started conditionally, as suggested below.

func startSpinner(message string) *spinner.Spinner {
	s := spinner.New(spinner.CharSets[9], 500*time.Millisecond, spinner.WithWriterFile(os.Stdout))
	if logLevel := logrus.GetLevel(); logLevel < logrus.DebugLevel {
		s.Prefix = message
		s.Start()
	}
	return s
}

DaliborKr added a commit to DaliborKr/toolbox that referenced this pull request Apr 23, 2026
In /src/cmd/create.go, the same pattern of spinner creation and
nil-safe stopping is repeated.

Extract this into startSpinner() and stopSpinner() helper functions so
that future callers can use spinners without duplicating the code.
Replace the existing inline spinner code in createContainer() and
pullImage() with calls to these new helpers.

containers#1781

Signed-off-by: Dalibor Kricka <dalidalk@seznam.cz>
DaliborKr added a commit to DaliborKr/toolbox that referenced this pull request Apr 23, 2026
…atching

Add IsSupportedDistroImage(), which iterates over all supported distros
and checks if the image basename matches any of them. This will be used
by the architecture resolution code to decide whether to parse
architecture suffixes from image tags, as this should be done only for
natively supported images [1].

[1] Toolbx supported distributions: https://containertoolbx.org/distros/

containers#1781

Signed-off-by: Dalibor Kricka <dalidalk@seznam.cz>
@DaliborKr DaliborKr force-pushed the pr02-spinner-utils branch from 051b8d7 to 4afa672 Compare April 23, 2026 05:01
@softwarefactory-project-zuul
Copy link
Copy Markdown

DaliborKr added 2 commits May 10, 2026 22:12
In /src/cmd/create.go, the same pattern of spinner creation and
nil-safe stopping is repeated.

Extract this into startSpinner() and stopSpinner() helper functions so
that future callers can use spinners without duplicating the code.
Replace the existing inline spinner code in createContainer() and
pullImage() with calls to these new helpers.

containers#1781

Signed-off-by: Dalibor Kricka <dalidalk@seznam.cz>
…atching

Add IsSupportedDistroImage(), which iterates over all supported distros
and checks if the image basename matches any of them. This will be used
by the architecture resolution code to decide whether to parse
architecture suffixes from image tags, as this should be done only for
natively supported images [1].

[1] Toolbx supported distributions: https://containertoolbx.org/distros/

containers#1781

Signed-off-by: Dalibor Kricka <dalidalk@seznam.cz>
@DaliborKr DaliborKr force-pushed the pr02-spinner-utils branch from 4afa672 to 80c972b Compare May 10, 2026 21:33
@centosinfra-prod-github-app
Copy link
Copy Markdown

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.

1 participant