diff --git a/docs/docs/segment-dotnet.md b/docs/docs/segment-dotnet.md index ea6d03898efd..0293edc4dff4 100644 --- a/docs/docs/segment-dotnet.md +++ b/docs/docs/segment-dotnet.md @@ -27,6 +27,7 @@ Display the currently active .NET SDK version. - display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `dotnet` is present - defaults to `true` +- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed diff --git a/docs/docs/segment-golang.md b/docs/docs/segment-golang.md index 13e21d0a02eb..b934c81faf25 100644 --- a/docs/docs/segment-golang.md +++ b/docs/docs/segment-golang.md @@ -26,6 +26,7 @@ Display the currently active golang version. ## Properties - display_version: `boolean` - display the golang version - defaults to `true` +- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed diff --git a/docs/docs/segment-julia.md b/docs/docs/segment-julia.md index f6b5fb8de3fa..52c219ea0be8 100644 --- a/docs/docs/segment-julia.md +++ b/docs/docs/segment-julia.md @@ -26,6 +26,7 @@ Display the currently active julia version. ## Properties - display_version: `boolean` - display the julia version - defaults to `true` +- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed diff --git a/docs/docs/segment-node.md b/docs/docs/segment-node.md index 0ca463208272..27645a902678 100644 --- a/docs/docs/segment-node.md +++ b/docs/docs/segment-node.md @@ -26,6 +26,7 @@ Display the currently active node version. ## Properties - display_version: `boolean` - display the node version - defaults to `true` +- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: The segment is always displayed diff --git a/docs/docs/segment-python.md b/docs/docs/segment-python.md index 63c2ebb82dea..8864edbea0b3 100644 --- a/docs/docs/segment-python.md +++ b/docs/docs/segment-python.md @@ -30,6 +30,7 @@ Supports conda, virtualenv and pyenv. - display_default_env: `boolean` - show the name of the virtualenv when it's default (`system`, `base`) or not - defaults to `true` - display_version: `boolean` - display the python version - defaults to `true` +- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed diff --git a/docs/docs/segment-ruby.md b/docs/docs/segment-ruby.md index 32a32de85255..39ab86f33d26 100644 --- a/docs/docs/segment-ruby.md +++ b/docs/docs/segment-ruby.md @@ -26,6 +26,7 @@ Display the currently active ruby version. ## Properties - display_version: `boolean` - display the ruby version - defaults to `true` +- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed diff --git a/src/segment_language.go b/src/segment_language.go index 017d7e7f1691..0aab485e4c54 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -98,9 +98,13 @@ func (l *language) string() string { } err := l.setVersion() - if err != nil { + displayError := l.props.getBool(DisplayError, true) + if err != nil && displayError { return err.Error() } + if err != nil { + return "" + } if l.props.getBool(EnableHyperlink, false) { return l.activeCommand.buildVersionURL(l.versionURLTemplate) diff --git a/src/segment_language_test.go b/src/segment_language_test.go index 7e571f906b32..b9fecb0b9e43 100644 --- a/src/segment_language_test.go +++ b/src/segment_language_test.go @@ -261,6 +261,24 @@ func TestLanguageEnabledMissingCommandCustomText(t *testing.T) { assert.Equal(t, expected, lang.string(), "unicorn is available and uni and corn files are found") } +func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) { + props := map[Property]interface{}{ + MissingCommandText: "missing", + DisplayError: false, + } + args := &languageArgs{ + commands: []*cmd{}, + extensions: []string{uni, corn}, + enabledExtensions: []string{uni, corn}, + enabledCommands: []string{"unicorn"}, + version: universion, + properties: props, + } + lang := bootStrapLanguageTest(args) + assert.True(t, lang.enabled()) + assert.Equal(t, "", lang.string()) +} + func TestLanguageEnabledCommandExitCode(t *testing.T) { expected := 200 args := &languageArgs{