v icon indicating copy to clipboard operation
v copied to clipboard

`hostname()` and `loginname()` have differing semantics between platforms

Open rivy opened this issue 3 years ago • 2 comments

Describe the bug

For *nix, hostname() and loginname() return '' upon failure. But, the WinOS implementations return an error message string upon failure, which makes it difficult to determine if the result is correct or a failure.

Possible Solution

Likely the best technically correct fix would be to change them all to return Result.

Barring that, at a minimum, change the WinOS implementation to simply return '' upon failure in a similar manner to the *nix version.

V version

V 0.3.2 776fbdf

Environment details (OS name and version, etc.)

OS: windows, Microsoft Windows 10 Pro v19044 64-bit Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
CC version: cc (Rev5, Built by MSYS2 project) 10.3.0

getwd: C:\Users\Roy\OneDrive\Projects\vlang\v.coreutils vmodules: C:\Users\Roy.vmodules vroot: C:\Users\Roy\AppData\Local\scoop\apps\v\latest vexe: C:\Users\Roy\AppData\Local\scoop\apps\v\latest\v.exe vexe mtime: 2022-12-24 20:59:17 is vroot writable: true is vmodules writable: true V full version: V 0.3.2 992621b.776fbdf

Git version: git version 2.29.2.windows.2 Git vroot status: weekly.2022.51-2-g776fbdfb (58 commit(s) behind V master) .git/config present: true thirdparty/tcc status: thirdparty-windows-amd64 cb89a4fe

Notes

I'm happy to submit a PR if you have a suggested direction.

rivy avatar Jan 03 '23 17:01 rivy

I would say returning a Result is the more correct way of handling the problem. The implementation details can then be "hidden" in the routine.

JalonSolov avatar Jan 03 '23 17:01 JalonSolov

Good find @rivy

Should behave like Go's os.Hostname()

https://pkg.go.dev/os#Hostname

Picked up by @paulyelesin

medvednikov avatar Feb 16 '23 15:02 medvednikov

Fixed in #17414

JalonSolov avatar Mar 07 '23 14:03 JalonSolov

Fixed in #17414

I hadn't had time to circle back around to this yet. Thank you for the fix!

rivy avatar Mar 07 '23 15:03 rivy