From bee4e23a757b687fbebdb7d8d8ccb98106481c29 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Feb 2026 16:11:41 +0000 Subject: [PATCH] =?UTF-8?q?chore:=20fmt.Errorf(static)=20=E2=86=92=20error?= =?UTF-8?q?s.New?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- node/bundle.go | 5 +++-- node/controller.go | 15 ++++++++------- node/dispatcher.go | 5 +++-- node/identity.go | 3 ++- node/peer.go | 7 ++++--- node/protocol.go | 3 ++- node/transport.go | 7 ++++--- node/worker.go | 15 ++++++++------- ueps/reader.go | 15 +++++++-------- 9 files changed, 41 insertions(+), 34 deletions(-) diff --git a/node/bundle.go b/node/bundle.go index baf1f3e..ecc2513 100644 --- a/node/bundle.go +++ b/node/bundle.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "os" @@ -134,7 +135,7 @@ func CreateMinerBundle(minerPath string, profileJSON []byte, name string, passwo func ExtractProfileBundle(bundle *Bundle, password string) ([]byte, error) { // Verify checksum first if calculateChecksum(bundle.Data) != bundle.Checksum { - return nil, fmt.Errorf("checksum mismatch - bundle may be corrupted") + return nil, errors.New("checksum mismatch - bundle may be corrupted") } // If it's unencrypted JSON, just return it @@ -155,7 +156,7 @@ func ExtractProfileBundle(bundle *Bundle, password string) ([]byte, error) { func ExtractMinerBundle(bundle *Bundle, password string, destDir string) (string, []byte, error) { // Verify checksum if calculateChecksum(bundle.Data) != bundle.Checksum { - return "", nil, fmt.Errorf("checksum mismatch - bundle may be corrupted") + return "", nil, errors.New("checksum mismatch - bundle may be corrupted") } // Decrypt STIM format diff --git a/node/controller.go b/node/controller.go index 6432f3d..7373ab6 100644 --- a/node/controller.go +++ b/node/controller.go @@ -3,6 +3,7 @@ package node import ( "context" "encoding/json" + "errors" "fmt" "sync" "time" @@ -106,7 +107,7 @@ func (c *Controller) sendRequest(peerID string, msg *Message, timeout time.Durat case resp := <-respCh: return resp, nil case <-ctx.Done(): - return nil, fmt.Errorf("request timeout") + return nil, errors.New("request timeout") } } @@ -114,7 +115,7 @@ func (c *Controller) sendRequest(peerID string, msg *Message, timeout time.Durat func (c *Controller) GetRemoteStats(peerID string) (*StatsPayload, error) { identity := c.node.GetIdentity() if identity == nil { - return nil, fmt.Errorf("node identity not initialized") + return nil, errors.New("node identity not initialized") } msg, err := NewMessage(MsgGetStats, identity.ID, peerID, nil) @@ -139,11 +140,11 @@ func (c *Controller) GetRemoteStats(peerID string) (*StatsPayload, error) { func (c *Controller) StartRemoteMiner(peerID, minerType, profileID string, configOverride json.RawMessage) error { identity := c.node.GetIdentity() if identity == nil { - return fmt.Errorf("node identity not initialized") + return errors.New("node identity not initialized") } if minerType == "" { - return fmt.Errorf("miner type is required") + return errors.New("miner type is required") } payload := StartMinerPayload{ @@ -178,7 +179,7 @@ func (c *Controller) StartRemoteMiner(peerID, minerType, profileID string, confi func (c *Controller) StopRemoteMiner(peerID, minerName string) error { identity := c.node.GetIdentity() if identity == nil { - return fmt.Errorf("node identity not initialized") + return errors.New("node identity not initialized") } payload := StopMinerPayload{ @@ -211,7 +212,7 @@ func (c *Controller) StopRemoteMiner(peerID, minerName string) error { func (c *Controller) GetRemoteLogs(peerID, minerName string, lines int) ([]string, error) { identity := c.node.GetIdentity() if identity == nil { - return nil, fmt.Errorf("node identity not initialized") + return nil, errors.New("node identity not initialized") } payload := GetLogsPayload{ @@ -270,7 +271,7 @@ func (c *Controller) GetAllStats() map[string]*StatsPayload { func (c *Controller) PingPeer(peerID string) (float64, error) { identity := c.node.GetIdentity() if identity == nil { - return 0, fmt.Errorf("node identity not initialized") + return 0, errors.New("node identity not initialized") } sentAt := time.Now() diff --git a/node/dispatcher.go b/node/dispatcher.go index 33f59e9..668700e 100644 --- a/node/dispatcher.go +++ b/node/dispatcher.go @@ -1,6 +1,7 @@ package node import ( + "errors" "fmt" "iter" "sync" @@ -136,8 +137,8 @@ var ( // ErrUnknownIntent is returned when no handler is registered for the // packet's IntentID. - ErrUnknownIntent = fmt.Errorf("packet dropped: unknown intent") + ErrUnknownIntent = errors.New("packet dropped: unknown intent") // ErrNilPacket is returned when a nil packet is passed to Dispatch. - ErrNilPacket = fmt.Errorf("dispatch: nil packet") + ErrNilPacket = errors.New("dispatch: nil packet") ) diff --git a/node/identity.go b/node/identity.go index 67683b8..32d78cf 100644 --- a/node/identity.go +++ b/node/identity.go @@ -8,6 +8,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -173,7 +174,7 @@ func (n *NodeManager) DeriveSharedSecret(peerPubKeyBase64 string) ([]byte, error defer n.mu.RUnlock() if n.privateKey == nil { - return nil, fmt.Errorf("node identity not initialized") + return nil, errors.New("node identity not initialized") } // Load peer's public key diff --git a/node/peer.go b/node/peer.go index bf05184..71dcf09 100644 --- a/node/peer.go +++ b/node/peer.go @@ -2,6 +2,7 @@ package node import ( "encoding/json" + "errors" "fmt" "iter" "maps" @@ -12,8 +13,8 @@ import ( "sync" "time" + poindexter "forge.lthn.ai/Snider/Poindexter" "forge.lthn.ai/core/go-p2p/logging" - "forge.lthn.ai/Snider/Poindexter" "github.com/adrg/xdg" ) @@ -84,7 +85,7 @@ func validatePeerName(name string) error { return fmt.Errorf("peer name too long (max %d characters)", PeerNameMaxLength) } if !peerNameRegex.MatchString(name) { - return fmt.Errorf("peer name contains invalid characters (use alphanumeric, hyphens, underscores, spaces)") + return errors.New("peer name contains invalid characters (use alphanumeric, hyphens, underscores, spaces)") } return nil } @@ -243,7 +244,7 @@ func (r *PeerRegistry) AddPeer(peer *Peer) error { if peer.ID == "" { r.mu.Unlock() - return fmt.Errorf("peer ID is required") + return errors.New("peer ID is required") } // Validate peer name (P2P-LOW-3) diff --git a/node/protocol.go b/node/protocol.go index c8f9d61..f75dce7 100644 --- a/node/protocol.go +++ b/node/protocol.go @@ -1,6 +1,7 @@ package node import ( + "errors" "fmt" ) @@ -24,7 +25,7 @@ type ResponseHandler struct{} // 3. If response type matches expected (returns error if not) func (h *ResponseHandler) ValidateResponse(resp *Message, expectedType MessageType) error { if resp == nil { - return fmt.Errorf("nil response") + return errors.New("nil response") } // Check for error response diff --git a/node/transport.go b/node/transport.go index 739e128..fc4b834 100644 --- a/node/transport.go +++ b/node/transport.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/base64" "encoding/json" + "errors" "fmt" "iter" "maps" @@ -621,7 +622,7 @@ func (t *Transport) performHandshake(pc *PeerConnection) error { identity := t.node.GetIdentity() if identity == nil { - return fmt.Errorf("node identity not initialized") + return errors.New("node identity not initialized") } // Generate challenge for the server to prove it has the matching private key @@ -689,10 +690,10 @@ func (t *Transport) performHandshake(pc *PeerConnection) error { // Verify the server's response to our challenge if len(ackPayload.ChallengeResponse) == 0 { - return fmt.Errorf("server did not provide challenge response") + return errors.New("server did not provide challenge response") } if !VerifyChallenge(challenge, ackPayload.ChallengeResponse, sharedSecret) { - return fmt.Errorf("challenge response verification failed: server may not have matching private key") + return errors.New("challenge response verification failed: server may not have matching private key") } // Store the shared secret for later use diff --git a/node/worker.go b/node/worker.go index 10b7ec6..604c5df 100644 --- a/node/worker.go +++ b/node/worker.go @@ -3,6 +3,7 @@ package node import ( "encoding/base64" "encoding/json" + "errors" "fmt" "path/filepath" "time" @@ -130,7 +131,7 @@ func (w *Worker) handlePing(msg *Message) (*Message, error) { func (w *Worker) handleGetStats(msg *Message) (*Message, error) { identity := w.node.GetIdentity() if identity == nil { - return nil, fmt.Errorf("node identity not initialized") + return nil, errors.New("node identity not initialized") } stats := StatsPayload{ @@ -193,7 +194,7 @@ func convertMinerStats(miner MinerInstance, rawStats any) MinerStatsItem { // handleStartMiner starts a miner with the given profile. func (w *Worker) handleStartMiner(msg *Message) (*Message, error) { if w.minerManager == nil { - return nil, fmt.Errorf("miner manager not configured") + return nil, errors.New("miner manager not configured") } var payload StartMinerPayload @@ -203,7 +204,7 @@ func (w *Worker) handleStartMiner(msg *Message) (*Message, error) { // Validate miner type is provided if payload.MinerType == "" { - return nil, fmt.Errorf("miner type is required") + return nil, errors.New("miner type is required") } // Get the config from the profile or use the override @@ -217,7 +218,7 @@ func (w *Worker) handleStartMiner(msg *Message) (*Message, error) { } config = profile } else { - return nil, fmt.Errorf("no config provided and no profile manager configured") + return nil, errors.New("no config provided and no profile manager configured") } // Start the miner @@ -240,7 +241,7 @@ func (w *Worker) handleStartMiner(msg *Message) (*Message, error) { // handleStopMiner stops a running miner. func (w *Worker) handleStopMiner(msg *Message) (*Message, error) { if w.minerManager == nil { - return nil, fmt.Errorf("miner manager not configured") + return nil, errors.New("miner manager not configured") } var payload StopMinerPayload @@ -263,7 +264,7 @@ func (w *Worker) handleStopMiner(msg *Message) (*Message, error) { // handleGetLogs returns console logs from a miner. func (w *Worker) handleGetLogs(msg *Message) (*Message, error) { if w.minerManager == nil { - return nil, fmt.Errorf("miner manager not configured") + return nil, errors.New("miner manager not configured") } var payload GetLogsPayload @@ -317,7 +318,7 @@ func (w *Worker) handleDeploy(conn *PeerConnection, msg *Message) (*Message, err switch bundle.Type { case BundleProfile: if w.profileManager == nil { - return nil, fmt.Errorf("profile manager not configured") + return nil, errors.New("profile manager not configured") } // Decrypt and extract profile data diff --git a/ueps/reader.go b/ueps/reader.go index d17b332..d588b50 100644 --- a/ueps/reader.go +++ b/ueps/reader.go @@ -7,7 +7,6 @@ import ( "crypto/sha256" "encoding/binary" "errors" - "fmt" "io" ) @@ -40,25 +39,25 @@ func ReadAndVerify(r *bufio.Reader, sharedSecret []byte) (*ParsedPacket, error) // Stop recording signedData here (HMAC covers headers + payload, but logic splits) // Actually, wait. The HMAC covers (Headers + Payload). // We need to read the payload to verify. - + // For this implementation, we read until EOF or a specific delimiter? - // In a TCP stream, we need a length. - // If you are using standard TCP, you typically prefix the WHOLE frame with + // In a TCP stream, we need a length. + // If you are using standard TCP, you typically prefix the WHOLE frame with // a 4-byte length. Assuming you handle that framing *before* calling this. - + // Reading the rest as payload: remaining, err := io.ReadAll(r) if err != nil { return nil, err } payload = remaining - + // Add 0xFF and payload to the buffer for signature check? // NO. In MarshalAndSign: // mac.Write(buf.Bytes()) // Headers // mac.Write(p.Payload) // Data // It did NOT write the 0xFF tag into the HMAC. - + break // Exit loop } @@ -128,7 +127,7 @@ func ReadAndVerify(r *bufio.Reader, sharedSecret []byte) (*ParsedPacket, error) if !hmac.Equal(signature, expectedMAC) { // Log this. This is a Threat Event. // "Axiom Violation: Integrity Check Failed" - return nil, fmt.Errorf("integrity violation: HMAC mismatch (ThreatScore +100)") + return nil, errors.New("integrity violation: HMAC mismatch (ThreatScore +100)") } return &ParsedPacket{