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

Signed-off-by: Nieves Montero <[email protected]>
  • Loading branch information
nievesmontero committed May 4, 2023
1 parent 3cfb6bf commit 9598f72
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 @@ -142,6 +142,10 @@ func preRun(cmd *cobra.Command, args []string) error {
if _, err := validateSubIDRanges(cmd, args, currentUser); err != nil {
return err
}
} else {
if !utils.IsInsideToolboxContainer() {
return createErrorNonToolboxContainer()
}
}

toolboxPath := os.Getenv("TOOLBOX_PATH")
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 9598f72

Please sign in to comment.