Repository navigation
Conversation
Several endpoints used by the CLI no longer exist upstream, which made
the affected commands panic with nil pointer / interface conversion
errors instead of failing gracefully.
Endpoints observed as removed (404):
- /machine/unreleased/ -> machines: panic in createFlex
- /user/profile/activity/ -> info -u: nil map -> TUI segfault
- /user/profile/basic/ (no id) -> replaced by /user/profile/basic/{id}
Changes:
- machines: tolerate missing/empty payloads, drop the hard exit when the
scheduled list is unavailable, and add a plain-text renderer for
non-TTY output instead of crashing under a pipe.
- info: stop requesting the removed activity endpoint, guard against nil
JSON bodies, and print the user profile (rank, owns, fortresses/pro
labs) as plain text when stdout is not a terminal.
- sherlocks: add the same non-TTY plain-text listing fallback.
- tui: never hand a nil tview primitive to a Flex (placeholder panels),
which removes the segfault seen when a section could not be loaded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several commands currently panic instead of failing gracefully because endpoints used by the CLI no longer exist in HTB's API v4. This PR makes those paths tolerant and adds a plain-text fallback for non-TTY usage.
Endpoints observed returning
404(verified againstlabs.hackthebox.com/api/v4)/machine/unreleased/htb-cli machinespanic: interface conversion: interface {} is nil, not []interface {}increateFlex/user/profile/activity/htb-cli info -u <user>Error fetching data for Activitythen nil primitive in TUI/user/profile/basic/(without id)htb-cli info -u <user>404— the route now requires/user/profile/basic/{id}(this part already works, the id is appended by the CLI)Still working:
/machine/paginated/,/machine/list/retired/paginated/,/user/profile/progress/fortress/{id},/user/profile/progress/prolab/{id},/sherlocks?state=*.Changes
cmd/machines.go— tolerate missing/empty payloads, drop the hardos.Exit(1)when the scheduled list is unavailable, and add a plain-text renderer used when stdout is not a TTY (previously instant panic under a pipe/redirect).cmd/info.go— stop requesting the removed activity endpoint, guard against non-map JSON bodies instead of a type assertion panic, and print the user profile (rank, owns, team, fortresses, Pro Labs) as plain text when stdout is not a terminal.cmd/sherlocks.go— same non-TTY plain-text listing fallback.lib/utils/tui.go— never hand aniltview primitive to aFlex; unavailable sections get a placeholder panel. This is what caused the segfault inDisplayInformationsGUI.Behaviour is unchanged when a real terminal is attached — the TUI is still used; only the failure modes are fixed.
Verification
Built with Go 1.27.3 on Debian 13, tested against a real (non-VIP) account:
TUI mode was also exercised under a pty: no panic, the
Scheduledpane shows a notice instead of crashing.go build ./...andgo vet ./...pass.Relation to #141
#141 (
HTB API and Sherlocks improvements) is a broader rewrite that also moves some calls to API v5 (/v5/machines?..., v5 activity). This PR is intentionally minimal and orthogonal: it does not change which data is fetched, only makes the current v4 behaviour non-fatal and usable without a TTY. If #141 lands first, themachines/infoparts here become redundant, but the non-TTY fallbacks and the nil-guard inlib/utils/tui.gostill apply.Happy to rebase or drop overlapping parts depending on what maintainers prefer.