Skip to content

Improved error handling in the use and switch commands#1114

Merged
morozov merged 1 commit intophpbrew:masterfrom
morozov:shell-error-handling
Dec 21, 2019
Merged

Improved error handling in the use and switch commands#1114
morozov merged 1 commit intophpbrew:masterfrom
morozov:shell-error-handling

Conversation

@morozov
Copy link
Contributor

@morozov morozov commented Dec 21, 2019

Prior to the fix, the commands didn't return proper exit code in the case of an error and didn't correctly handle the error exit code of the underlying env command.

Fish:

$ phpbrew use blah
PHP version blah is not installed.

$ echo $status
0

$ phpbrew switch blah
Invalid: command not found
~/.phpbrew/init (line 2):
Invalid argument blah
^
from sourcing file ~/.phpbrew/init
	called on line 794 of file ~/.phpbrew/phpbrew.fish

in function “__phpbrew_update_config”
	called on line 807 of file ~/.phpbrew/phpbrew.fish
	with parameter list “blah”

in function “__phpbrew_reinit”
	called on line 397 of file ~/.phpbrew/phpbrew.fish
	with parameter list “blah”

in function “phpbrew”
	called on standard input
	with parameter list “switch blah”

$ echo $status
0

$ cat ~/.phpbrew/init
Invalid argument blah

Bash:

$ phpbrew use blah
PHP version blah is not installed.

$ echo $?
0

$ phpbrew switch blah
Invalid: command not found

$ echo $?
0

$ cat ~/.phpbrew/init
Invalid argument blah

Prior to the fix, the commands didn't return the proper exit code in the case of an error and didn't correctly handle the error exit code of the underlying `env` command.

**Fish:**
```
$ phpbrew use blah
PHP version blah is not installed.

$ echo $status
0

$ phpbrew switch blah
Invalid: command not found
~/.phpbrew/init (line 2):
Invalid argument blah
^
from sourcing file ~/.phpbrew/init
	called on line 794 of file ~/.phpbrew/phpbrew.fish

in function “__phpbrew_update_config”
	called on line 807 of file ~/.phpbrew/phpbrew.fish
	with parameter list “blah”

in function “__phpbrew_reinit”
	called on line 397 of file ~/.phpbrew/phpbrew.fish
	with parameter list “blah”

in function “phpbrew”
	called on standard input
	with parameter list “switch blah”

$ echo $status
0

$ cat ~/.phpbrew/init
Invalid argument blah
```

**Bash:**
```
$ phpbrew use blah
PHP version blah is not installed.

$ echo $?
0

$ phpbrew switch blah
Invalid: command not found

$ echo $?
0

$ cat ~/.phpbrew/init
Invalid argument blah
```
@morozov morozov added this to the Release 1.25.0 milestone Dec 21, 2019
@morozov morozov self-assigned this Dec 21, 2019
@morozov morozov merged commit f4eff8a into phpbrew:master Dec 21, 2019
@morozov morozov deleted the shell-error-handling branch December 21, 2019 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant