Skip to content

Commit

Permalink
Improve the error message when running nested inside a non-Toolbx con…
Browse files Browse the repository at this point in the history
…tainer

Fixes issue #1183

Signed-off-by: Nieves Montero <nmontero@redhat.com>
  • Loading branch information
nievesmontero committed Nov 2, 2023
1 parent 154156d commit b287838
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func preRun(cmd *cobra.Command, args []string) error {
}
}

if utils.IsInsideContainer() && !utils.IsInsideToolboxContainer() {
return createErrorNonToolboxContainer()
}

toolboxPath := os.Getenv("TOOLBOX_PATH")

if toolboxPath == "" {
Expand Down
10 changes: 10 additions & 0 deletions src/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ func createErrorInvalidRelease(hint string) error {
return errors.New(errMsg)
}

func createErrorNonToolboxContainer() error {
var builder strings.Builder
fmt.Fprintf(&builder, "this is not a Toolbox container.\n")
fmt.Fprintf(&builder, "Toolbox is only meant to work with Toolbox containers.\n")
fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase)

errMsg := builder.String()
return errors.New(errMsg)
}

func getUsageForCommonCommands() string {
var builder strings.Builder
fmt.Fprintf(&builder, "create Create a new toolbox container\n")
Expand Down

0 comments on commit b287838

Please sign in to comment.