JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
15.88k stars 2.28k forks source link

32-bit exit codes and int type #819

Closed cdonnellytx closed 3 years ago

cdonnellytx commented 3 years ago

Prerequisites

Description

812 changed the dotnet.exe Windows exit code 0x80008091 to -2147450735. Unfortunately the dotnet prompt on 64-bit Windows now fails as the int type is apparently 64-bit in 64-bit Go.

Unfortunately I don't know what the best approach is here. Because the exit code ultimately comes from ProcessState.ExitCode(), which returns an int, it means the value will be different whether targeting a 32- or 64-bit architecture, and of course on a 32-bit architecture, int(0x80008091) returns an overflow error.

Environment

Steps to Reproduce

  1. Unzip attachment to C:\temp\exitcodebug or other suitable path
  2. In PowerShell, cd C:\temp\exitcodebug
  3. Run
    path\to\posh-windows-386.exe -config theme.json
    path\to\posh-windows-amd64.exe -config theme.json

Expected behavior:

both 386, amd64 show a warning symbol after the dotnet symbol

Actual behavior: 386 is correct, but amd64 says 'Executing dotnet with [--version]'

JanDeDobbeleer commented 3 years ago

@cdonnellytx we could go down the pragmatic route:

diff --git a/src/segment_dotnet.go b/src/segment_dotnet.go
index ac8d3891..96b8133f 100644
--- a/src/segment_dotnet.go
+++ b/src/segment_dotnet.go
@@ -1,5 +1,7 @@
 package main

+import "runtime"
+
 type dotnet struct {
    language *language
 }
@@ -19,8 +21,12 @@ func (d *dotnet) string() string {
    // Exit codes 145 and 0x80008091 are special indicators that dotnet
    // ran, but the current project config settings specify
    // use of an SDK that isn't installed.
+   exitCodeWindows := dotnetExitCodeWindows
+   if runtime.GOARCH == "amd64" {
+       exitCodeWindows = int(0x80008091)
+   }
    exitCode := d.language.exitCode
-   if exitCode == dotnetExitCodeWindows || exitCode == dotnetExitCodeUnix {
+   if exitCode == exitCodeWindows || exitCode == dotnetExitCodeUnix {
        return d.language.props.getString(UnsupportedDotnetVersionIcon, "\uf071 ")
    }

diff --git a/src/segment_dotnet_test.go b/src/segment_dotnet_test.go
index e13140f6..837372e9 100644
--- a/src/segment_dotnet_test.go
+++ b/src/segment_dotnet_test.go
@@ -1,6 +1,7 @@
 package main

 import (
+   "runtime"
    "testing"

    "github.com/stretchr/testify/assert"
@@ -84,11 +85,15 @@ func TestDotnetVersionUnsupported(t *testing.T) {
 }

 func TestDotnetVersionUnsupportedWindows(t *testing.T) {
+   exitCode := dotnetExitCodeWindows
+   if runtime.GOARCH == "amd64" {
+       exitCode = int(0x80008091)
+   }
    expected := "x"
    args := &dotnetArgs{
        enabled:         true,
        displayVersion:  true,
-       exitCode:        dotnetExitCodeWindows,
+       exitCode:        exitCode,
        unsupportedIcon: expected,
    }
    dotnet := bootStrapDotnetTest(args)
JanDeDobbeleer commented 3 years ago

@cdonnellytx had to really only include these from being used on that architecture but seems to compile. That should "in theory" also fix the issue.

cdonnellytx commented 3 years ago

Just realized -- you might also want to check for arm64 (either here or as part of #463).

JanDeDobbeleer commented 3 years ago

@cdonnellytx I'm doing that when go 1.17 lands which hopefully brings full windows ARM support

github-actions[bot] commented 3 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.