glab crash with wrong API url
<!---
Please read this!
Before opening a new issue, make sure to search for keywords in the issues
filtered by the "bug" label:
- https://gitlab.com/gitlab-org/cli/-/issues/?label_name%5B%5D=type%3A%3Abug
and verify the issue you're about to submit isn't a duplicate.
--->
### Checklist
<!-- Please test the latest versions, that will remove the possibility that you see a bug that is fixed in a newer version. -->
- [x] I'm using the latest version of the extension (Run `glab --version`)
- Extension version: _Put your extension version here_
- [x] Operating system and version: Fedora 43
- [x] Gitlab.com or self-managed instance? _both_
- [x] Run the command in debug mode (like `DEBUG=true glab mr list`) and attach any useful output
### Summary
Wrong URL validation causes panic crash
### Environment
<!--
on POSIX system (Linux, MacOS), run
bash -c 'printf -- "- OS: %s\n- SHELL: %s\n- TERM: %s\n- GLAB: %s" "$(uname -srm)" "$SHELL" "$TERM" "$(glab --version)"'
and replace the following section with the result.
If you use non-POSIX system, fill in the section manually:
- OS: Your operating system including version and architecture (Windows 11 - AMD64, MacOS Sonoma - ARM64)
- SHELL: Your shell (bash, fish, zsh, ...)
- TERM: Your terminal emulator (Kitty, Xterm2..)
- GLAB: result of running `glab --version` (glab version 1.32.0 (2023-08-18))
-->
- OS: Fedora 43
- SHELL: bash
- TERM: gnome-terminal
- GLAB: 1.89.0
<!--
Please include any other information that you believe might be relevant
in debugging. For example, you may include a shell framework like oh-my-zsh
or other customizations like editing the prompt (PS1, PS2, and others).
-->
Other:
### Steps to reproduce
Just run `glab api http://host:abc`
### What is the current _bug_ behavior?
Panics and creates a coredump
### What is the expected _correct_ behavior?
Not to panic and warn about wrong URL
### Relevant logs and/or screenshots
~~~
DEBUG=true glab api http://host:abc
[git remote -v]
[git config --get-regexp ^remote\..*\.glab-resolved(-base|-head)?$]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x55a58181984c]
goroutine 1 gp=0xc000002380 m=11 mp=0xc000600808 [running]:
panic({0x55a583524ba0?, 0x55a58435c3a0?})
/usr/lib/golang/src/runtime/panic.go:802 +0x168 fp=0xc000988bb8 sp=0xc000988b08 pc=0x55a581707d48
runtime.panicmem(...)
/usr/lib/golang/src/runtime/panic.go:262
runtime.sigpanic()
/usr/lib/golang/src/runtime/signal_unix.go:925 +0x359 fp=0xc000988c18 sp=0xc000988bb8 pc=0x55a58170a399
net/url.(*URL).String(0x55a583484820?)
/usr/lib/golang/src/net/url/url.go:859 +0x2c fp=0xc000988cf0 sp=0xc000988c18 pc=0x55a58181984c
gitlab.com/gitlab-org/cli/internal/api.NewHTTPRequest({0x55a5837b9358, 0xc0004ac380}, 0xc00019c630, {0x55a5828d9f99, 0x3}, 0x0?, {0x0, 0x0}, {0x0, 0x0, ...}, ...)
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/internal/api/client.go:393 +0x65 fp=0xc000988e60 sp=0xc000988cf0 pc=0x55a581ff2f45
gitlab.com/gitlab-org/cli/internal/commands/api.httpRequest({0x55a5837b9358, 0xc0004ac380}, 0xc00019c630, {0x55a5828d9f99, 0x3}, {0x7ffc6df380bc, 0xf}, {0x55a583574c40, 0xc000698570}, {0x0, ...})
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/internal/commands/api/http.go:78 +0x439 fp=0xc000989010 sp=0xc000988e60 pc=0x55a58210d6d9
gitlab.com/gitlab-org/cli/internal/commands/api.(*options).run(0xc0007a12b0, {0x55a5837b9358, 0xc0004ac380})
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/internal/commands/api/api.go:292 +0x785 fp=0xc000989208 sp=0xc000989010 pc=0x55a58210a8c5
gitlab.com/gitlab-org/cli/internal/commands/api.NewCmdApi.func1(0xc00084e308, {0xc000620350?, 0x4?, 0x55a5828daee1?})
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/internal/commands/api/api.go:185 +0x92 fp=0xc000989250 sp=0xc000989208 pc=0x55a582109cb2
github.com/spf13/cobra.(*Command).execute(0xc00084e308, {0xc000620330, 0x1, 0x1})
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/vendor/github.com/spf13/cobra/command.go:1015 +0xb02 fp=0xc0009893f8 sp=0xc000989250 pc=0x55a581922de2
github.com/spf13/cobra.(*Command).ExecuteC(0xc00083a008)
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/vendor/github.com/spf13/cobra/command.go:1148 +0x465 fp=0xc0009894e8 sp=0xc0009893f8 pc=0x55a581923725
github.com/spf13/cobra.(*Command).Execute(...)
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/vendor/github.com/spf13/cobra/command.go:1071
github.com/spf13/cobra.(*Command).ExecuteContext(...)
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/vendor/github.com/spf13/cobra/command.go:1064
github.com/charmbracelet/fang.Execute({0x55a5837b8b40, 0x55a5845e4420}, 0xc00083a008, {0xc00098fec8, 0x5, 0x6?})
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/vendor/github.com/charmbracelet/fang/fang.go:173 +0x392 fp=0xc00098fc30 sp=0xc0009894e8 pc=0x55a58195f612
main.main()
/builddir/build/BUILD/glab-1.89.0-build/cli-v1.89.0/cmd/glab/main.go:180 +0xaae fp=0xc00098ff50 sp=0xc00098fc30 pc=0x55a58285f9ee
runtime.main()
/usr/lib/golang/src/runtime/proc.go:285 +0x29d fp=0xc00098ffe0 sp=0xc00098ff50 pc=0x55a5816d355d
runtime.goexit({})
/usr/lib/golang/src/runtime/asm_amd64.s:1693 +0x1 fp=0xc00098ffe8 sp=0xc00098ffe0 pc=0x55a581710141
goroutine 2 gp=0xc000002e00 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/lib/golang/src/runtime/proc.go:460 +0xce fp=0xc000094fa8 sp=0xc000094f88 pc=0x55a58170826e
runtime.goparkunlock(...)
/usr/lib/golang/src/runtime/proc.go:466
runtime.forcegchelper()
/usr/lib/golang/src/runtime/proc.go:373 +0xb8 fp=0xc000094fe0 sp=0xc000094fa8 pc=0x55a5816d3898
runtime.goexit({})
/usr/lib/golang/src/runtime/asm_amd64.s:1693 +0x1 fp=0xc000094fe8 sp=0xc000094fe0 pc=0x55a581710141
created by runtime.init.8 in goroutine 1
/usr/lib/golang/src/runtime/proc.go:361 +0x1a
~~~
### Possible fixes
<!-- If you can, link to the line of code that might be responsible for the problem -->
Merge request will be attached.
issue