ax(node): replace direct encoding/json with package-level UnmarshalJSON wrapper
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

worker.go imported encoding/json directly and called json.Unmarshal at two
call sites. bufpool.go already provided MarshalJSON as the package wrapper;
add matching UnmarshalJSON and route both worker.go call sites through it,
removing the encoding/json import from worker.go.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 16:42:45 +01:00
parent 3c9ff897f2
commit b4c73147fe
No known key found for this signature in database
GPG key ID: AF404715446AEB41
2 changed files with 8 additions and 3 deletions

View file

@ -29,6 +29,12 @@ func putBuffer(buffer *bytes.Buffer) {
}
}
// var msg Message
// if err := UnmarshalJSON(data, &msg); err != nil { return nil, err }
func UnmarshalJSON(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
// data, err := MarshalJSON(msg)
// if err != nil { return nil, err }
func MarshalJSON(v interface{}) ([]byte, error) {

View file

@ -2,7 +2,6 @@ package node
import (
"encoding/base64"
"encoding/json"
"fmt"
"path"
"time"
@ -341,7 +340,7 @@ func (worker *Worker) handleDeploy(conn *PeerConnection, msg *Message) (*Message
// Unmarshal into interface{} to pass to ProfileManager
var profile interface{}
if err := json.Unmarshal(profileData, &profile); err != nil {
if err := UnmarshalJSON(profileData, &profile); err != nil {
return nil, fmt.Errorf("invalid profile data JSON: %w", err)
}
@ -381,7 +380,7 @@ func (worker *Worker) handleDeploy(conn *PeerConnection, msg *Message) (*Message
// If the bundle contained a profile config, save it
if len(profileData) > 0 && worker.profileManager != nil {
var profile interface{}
if err := json.Unmarshal(profileData, &profile); err != nil {
if err := UnmarshalJSON(profileData, &profile); err != nil {
logging.Warn("failed to parse profile from miner bundle", logging.Fields{"error": err})
} else {
if err := worker.profileManager.SaveProfile(profile); err != nil {