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 May 10, 2023
1 parent 3cfb6bf commit fcb73d2
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ func preRun(cmd *cobra.Command, args []string) error {
}
}

logrus.Debugf("Before checking inside a toolbox container")
if utils.IsInsideContainer() && !utils.IsInsideToolboxContainer() {
logrus.Debugf("Checking if a toolbox container")
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
1 change: 1 addition & 0 deletions test/system/001-version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers.bash'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
}

Expand Down
1 change: 1 addition & 0 deletions test/system/002-help.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers.bash'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
}

Expand Down
1 change: 1 addition & 0 deletions test/system/101-create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
cleanup_containers
}
Expand Down
1 change: 1 addition & 0 deletions test/system/103-container.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
cleanup_containers
}
Expand Down
2 changes: 2 additions & 0 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
cleanup_containers
}
Expand Down Expand Up @@ -606,6 +607,7 @@ teardown() {
assert_failure
assert [ ${#lines[@]} -eq 0 ]
lines=("${stderr_lines[@]}")
echo "${lines[0]}"
assert_line --index 0 "bash: line 1: exec: $cmd: not found"
assert_line --index 1 "Error: command $cmd not found in container $(get_latest_container_name)"
assert [ ${#stderr_lines[@]} -eq 2 ]
Expand Down
1 change: 1 addition & 0 deletions test/system/105-enter.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
cleanup_containers
}
Expand Down
1 change: 1 addition & 0 deletions test/system/106-rm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
cleanup_containers
}
Expand Down
1 change: 1 addition & 0 deletions test/system/107-rmi.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
cleanup_all
}
Expand Down
1 change: 1 addition & 0 deletions test/system/108-completion.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'

setup() {
bats_require_minimum_version 1.5.0
_setup_environment
}

Expand Down

0 comments on commit fcb73d2

Please sign in to comment.