-
Notifications
You must be signed in to change notification settings - Fork 2
chore(staticcheck): resolve SA1019 in libvirt and generated protobuf #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
64dfd86
016fd33
22aa23b
5d84594
534ea70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,10 +22,22 @@ import ( | |||||||||
| "time" | ||||||||||
|
|
||||||||||
| "github.com/digitalocean/go-libvirt" | ||||||||||
| libvirtsocket "github.com/digitalocean/go-libvirt/socket" | ||||||||||
| "github.com/google/uuid" | ||||||||||
| "github.com/poyrazk/thecloud/internal/core/ports" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| type libvirtUnixDialer struct { | ||||||||||
| uri string | ||||||||||
| timeout time.Duration | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var _ libvirtsocket.Dialer = (*libvirtUnixDialer)(nil) | ||||||||||
|
|
||||||||||
| func (d *libvirtUnixDialer) Dial() (net.Conn, error) { | ||||||||||
| return net.DialTimeout("unix", d.uri, d.timeout) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const ( | ||||||||||
| defaultPoolName = "default" | ||||||||||
| userDataFileName = "user-data" | ||||||||||
|
|
@@ -110,8 +122,8 @@ func NewLibvirtAdapter(logger *slog.Logger, uri string) (*LibvirtAdapter, error) | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| //nolint:staticcheck | ||||||||||
| l := libvirt.New(c) | ||||||||||
| _ = c.Close() | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't silently drop the probe socket Line 125 discards the only signal that the preflight socket cleanup failed. At least log it so init-time socket issues do not disappear during adapter setup. 🛠️ Suggested fix- _ = c.Close()
+ if err := c.Close(); err != nil {
+ logger.Warn("failed to close preflight libvirt socket", "uri", uri, "error", err)
+ }As per coding guidelines, "Do not use silent failures - avoid blank identifier assignment like 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| l := libvirt.NewWithDialer(&libvirtUnixDialer{uri: uri, timeout: 2 * time.Second}) | ||||||||||
|
||||||||||
| adapter := &LibvirtAdapter{ | ||||||||||
| client: &RealLibvirtClient{conn: l}, | ||||||||||
| logger: logger, | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: poyrazK/thecloud
Length of output: 636
🏁 Script executed:
Repository: poyrazK/thecloud
Length of output: 2113
🌐 Web query:
go-libvirt socket.Dialer dialers.NewLocal WithSocket WithLocalTimeout API documentation💡 Result:
The go-libvirt library (github.com/digitalocean/go-libvirt) provides a socket dialing API in the socket/dialers subpackage for connecting to libvirt daemons via UNIX sockets, TCP, TLS, SSH, etc. Key components: - socket.Dialer is the interface: type Dialer interface { Dial (net.Conn, error) } - dialers.NewLocal(opts ...LocalOption) creates a local (UNIX socket) dialer. It is the default for connecting to a locally running libvirt socket. - dialers.WithSocket(socket string) LocalOption: Specifies a custom UNIX socket path (e.g., dialers.NewLocal(dialers.WithSocket("/var/run/libvirt/virtqemud-sock")) for modular daemons). - dialers.WithLocalTimeout(timeout time.Duration) LocalOption: Sets the dial timeout for the local connection. Usage example from sources: dialer := dialers.NewLocal(dialers.WithSocket("/path/to/socket"), dialers.WithLocalTimeout(5*time.Second)) lv := libvirt.NewWithDialer(dialer) lv.Connect This is used internally by libvirt.ConnectToURI for "unix" transports, parsing ?socket= from the URI. Official documentation: pkg.go.dev/github.com/digitalocean/go-libvirt/socket/dialers (updated Feb 2026). Source code examples in github.com/digitalocean/go-libvirt/tree/main/socket/dialers and connect_uri.go.
Citations:
Handle the error from
Close()at line 125; do not silently ignore it.The probe connection must have its error handled explicitly. Currently
_ = c.Close()violates the guideline prohibiting silent failures via blank identifier assignment.If the error is intentionally ignored (e.g., best-effort cleanup before reconnection), capture it explicitly or wrap the close in a helper that documents the intent.
Optional: Replace the custom
libvirtUnixDialerwith the upstream local dialer.The pinned
go-libvirtversion (v0.0.0-20260106181248-56be673cd6a5) includesdialers.NewLocal(...)and its options (WithSocket,WithLocalTimeout), which provide the same functionality more idiomatically:Suggested refactoring
This removes the custom type and aligns with the upstream library's design.
🤖 Prompt for AI Agents