Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: check all error returns (errcheck)

Mario86c2a75a1dd4
diff --git a/cmd_connect.go b/cmd_connect.go
index 87e49d6f..02df516e 100644
--- a/cmd_connect.go
+++ b/cmd_connect.go
@@ -57,7 +57,7 @@ func handleConnectCommand() {
fmt.Fprintf(os.Stderr, "connect failed: %v\n", err)
os.Exit(1)
}
- defer res.Body.Close()
+ defer func() { _ = res.Body.Close() }()
if res.StatusCode != http.StatusOK {
body, _ := io.ReadAll(io.LimitReader(res.Body, 8<<10))
diff --git a/cmd_dashboard.go b/cmd_dashboard.go
index a9050e7e..06ba8706 100644
--- a/cmd_dashboard.go
+++ b/cmd_dashboard.go
@@ -25,7 +25,10 @@ func runDashboard() {
slog.Info("🦀 Pinchtab Dashboard", "port", dashPort)
profilesDir := filepath.Join(stateDir, "profiles")
- os.MkdirAll(profilesDir, 0755)
+ if err := os.MkdirAll(profilesDir, 0755); err != nil {
+ slog.Error("cannot create profiles dir", "err", err)
+ os.Exit(1)
+ }
profMgr := NewProfileManager(profilesDir)
dashboard := NewDashboard(nil)
@@ -94,7 +97,9 @@ func runDashboard() {
defaultProfile = "default"
}
- os.MkdirAll(filepath.Join(profilesDir, defaultProfile, "Default"), 0755)
+ if err := os.MkdirAll(filepath.Join(profilesDir, defaultProfile, "Default"), 0755); err != nil {
+ slog.Warn("failed to create default profile dir", "err", err)
+ }
go func() {
@@ -119,7 +124,9 @@ func runDashboard() {
orchestrator.Shutdown()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
- srv.Shutdown(ctx)
+ if err := srv.Shutdown(ctx); err != nil {
+ slog.Error("shutdown http", "err", err)
+ }
})
}
@@ -178,7 +185,7 @@ func proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) {
jsonErr(w, 502, fmt.Errorf("instance unreachable: %w", err))
return
}
- defer resp.Body.Close()
+ defer func() { _ = resp.Body.Close() }()
for k, vv := range resp.Header {
for _, v := range vv {
@@ -191,7 +198,7 @@ func proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) {
for {
n, err := resp.Body.Read(buf)
if n > 0 {
- w.Write(buf[:n])
+ _, _ = w.Write(buf[:n])
if f, ok := w.(http.Flusher); ok {
f.Flush()
}
diff --git a/dashboard.go b/dashboard.go
index 01b0d58c..3902b42b 100644
--- a/dashboard.go
+++ b/dashboard.go
@@ -196,14 +196,14 @@ func (d *Dashboard) handleSSE(w http.ResponseWriter, r *http.Request) {
agents := d.GetAgents()
data, _ := json.Marshal(agents)
- fmt.Fprintf(w, "event: init\ndata: %s\n\n", data)
+ _, _ = fmt.Fprintf(w, "event: init\ndata: %s\n\n", data)
flusher.Flush()
for {
select {
case evt := <-ch:
data, _ := json.Marshal(evt)
- fmt.Fprintf(w, "event: action\ndata: %s\n\n", data)
+ _, _ = fmt.Fprintf(w, "event: action\ndata: %s\n\n", data)
flusher.Flush()
case <-r.Context().Done():
return
@@ -217,7 +217,7 @@ func (d *Dashboard) handleDashboardUI(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
data, _ := dashboardFS.ReadFile("dashboard/dashboard.html")
- w.Write(data)
+ _, _ = w.Write(data)
}
func (d *Dashboard) withNoCache(next http.Handler) http.Handler {
diff --git a/dashboard_test.go b/dashboard_test.go
index e040ecc0..6ac117ea 100644
--- a/dashboard_test.go
+++ b/dashboard_test.go
@@ -93,7 +93,7 @@ func TestDashboardHandlerAgents(t *testing.T) {
}
var agents []AgentActivity
- json.NewDecoder(w.Body).Decode(&agents)
+ _ = json.NewDecoder(w.Body).Decode(&agents)
if len(agents) != 1 || agents[0].AgentID != "test-agent" {
t.Errorf("unexpected agents: %+v", agents)
}
@@ -140,7 +140,7 @@ func TestDashboardSSEInit(t *testing.T) {
return
}
if resp != nil {
- defer resp.Body.Close()
+ defer func() { _ = resp.Body.Close() }()
if resp.Header.Get("Content-Type") != "text/event-stream" {
t.Errorf("expected text/event-stream, got %s", resp.Header.Get("Content-Type"))
}
diff --git a/integration_test.go b/integration_test.go
index 2196a269..ff29fb0c 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -262,7 +262,7 @@ func TestFingerprintRotation(t *testing.T) {
}
var rotateResp map[string]any
- json.NewDecoder(resp.Body).Decode(&rotateResp)
+ _ = json.NewDecoder(resp.Body).Decode(&rotateResp)
fp, ok := rotateResp["fingerprint"].(map[string]any)
if !ok {
@@ -334,7 +334,7 @@ func TestStealthStatusEndpoint(t *testing.T) {
}
var result map[string]any
- json.NewDecoder(resp.Body).Decode(&result)
+ _ = json.NewDecoder(resp.Body).Decode(&result)
score, _ := result["score"].(float64)
if score < 50 {
diff --git a/orchestrator_handlers.go b/orchestrator_handlers.go
index 0209ae9f..637b437c 100644
--- a/orchestrator_handlers.go
+++ b/orchestrator_handlers.go
@@ -114,7 +114,7 @@ func (o *Orchestrator) handleLogs(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Content-Type", "text/plain")
- w.Write([]byte(logs))
+ _, _ = w.Write([]byte(logs))
}
func (o *Orchestrator) handleAllTabs(w http.ResponseWriter, r *http.Request) {
diff --git a/orchestrator_runtime.go b/orchestrator_runtime.go
index d4fda4d1..b303447e 100644
--- a/orchestrator_runtime.go
+++ b/orchestrator_runtime.go
@@ -44,9 +44,13 @@ func (o *Orchestrator) Launch(name, port string, headless bool) (*Instance, erro
}
profilePath := filepath.Join(o.baseDir, name)
- os.MkdirAll(filepath.Join(profilePath, "Default"), 0755)
+ if err := os.MkdirAll(filepath.Join(profilePath, "Default"), 0755); err != nil {
+ return nil, fmt.Errorf("create profile dir: %w", err)
+ }
instanceStateDir := filepath.Join(profilePath, ".pinchtab-state")
- os.MkdirAll(instanceStateDir, 0755)
+ if err := os.MkdirAll(instanceStateDir, 0755); err != nil {
+ return nil, fmt.Errorf("create state dir: %w", err)
+ }
ctx, cancel := context.WithCancel(context.Background())
@@ -123,7 +127,7 @@ func (o *Orchestrator) monitor(inst *Instance) {
for _, baseURL := range instanceBaseURLs(inst.Port) {
resp, err := o.client.Get(baseURL + "/health")
if err == nil {
- resp.Body.Close()
+ _ = resp.Body.Close()
lastProbe = fmt.Sprintf("%s -> HTTP %d", baseURL, resp.StatusCode)
if isInstanceHealthyStatus(resp.StatusCode) {
healthy = true
@@ -214,7 +218,7 @@ func (o *Orchestrator) Stop(id string) error {
req, _ := http.NewRequestWithContext(reqCtx, http.MethodPost, inst.URL+"/shutdown", nil)
resp, err := o.client.Do(req)
if err == nil {
- resp.Body.Close()
+ _ = resp.Body.Close()
}
if waitForProcessExit(inst.PID, 5*time.Second) {
@@ -407,7 +411,7 @@ func (o *Orchestrator) fetchTabs(baseURL string) ([]remoteTab, error) {
if err != nil {
return nil, err
}
- defer resp.Body.Close()
+ defer func() { _ = resp.Body.Close() }()
var tabs []remoteTab
if err := json.NewDecoder(resp.Body).Decode(&tabs); err != nil {
diff --git a/profiles_handlers.go b/profiles_handlers.go
index 8882fadb..15ce17f1 100644
--- a/profiles_handlers.go
+++ b/profiles_handlers.go
@@ -121,7 +121,7 @@ func profileQueryInt(r *http.Request, key string, def int) int {
return def
}
var n int
- fmt.Sscanf(s, "%d", &n)
+ _, _ = fmt.Sscanf(s, "%d", &n)
if n <= 0 {
return def
}
diff --git a/profiles_manager.go b/profiles_manager.go
index cbda9845..8c1681a3 100644
--- a/profiles_manager.go
+++ b/profiles_manager.go
@@ -32,7 +32,7 @@ type ProfileInfo struct {
}
func NewProfileManager(baseDir string) *ProfileManager {
- os.MkdirAll(baseDir, 0755)
+ _ = os.MkdirAll(baseDir, 0755)
return &ProfileManager{
baseDir: baseDir,
tracker: NewActionTracker(),
@@ -116,7 +116,9 @@ func (pm *ProfileManager) Import(name, sourcePath string) error {
return fmt.Errorf("copy failed: %w", err)
}
- os.WriteFile(filepath.Join(dest, ".pinchtab-imported"), []byte(sourcePath), 0644)
+ if err := os.WriteFile(filepath.Join(dest, ".pinchtab-imported"), []byte(sourcePath), 0644); err != nil {
+ slog.Warn("failed to write import marker", "err", err)
+ }
return nil
}
@@ -167,7 +169,7 @@ func (pm *ProfileManager) Reset(name string) error {
}
}
for _, f := range nukeFiles {
- os.Remove(filepath.Join(dir, f))
+ _ = os.Remove(filepath.Join(dir, f))
}
slog.Info("profile reset", "name", name)
@@ -195,7 +197,7 @@ func (pm *ProfileManager) Analytics(name string) AnalyticsReport {
func dirSizeMB(path string) float64 {
var total int64
- filepath.WalkDir(path, func(_ string, entry fs.DirEntry, err error) error {
+ _ = filepath.WalkDir(path, func(_ string, entry fs.DirEntry, err error) error {
if err != nil || entry.IsDir() {
return nil
}
diff --git a/profiles_test.go b/profiles_test.go
index 541e36e0..91742eae 100644
--- a/profiles_test.go
+++ b/profiles_test.go
@@ -38,7 +38,7 @@ func TestProfileManagerCreateDuplicate(t *testing.T) {
dir := t.TempDir()
pm := NewProfileManager(dir)
- pm.Create("dup")
+ _ = pm.Create("dup")
err := pm.Create("dup")
if err == nil {
t.Fatal("expected error on duplicate create")
@@ -50,8 +50,8 @@ func TestProfileManagerImport(t *testing.T) {
pm := NewProfileManager(dir)
src := filepath.Join(t.TempDir(), "chrome-src")
- os.MkdirAll(filepath.Join(src, "Default"), 0755)
- os.WriteFile(filepath.Join(src, "Default", "Preferences"), []byte(`{}`), 0644)
+ _ = os.MkdirAll(filepath.Join(src, "Default"), 0755)
+ _ = os.WriteFile(filepath.Join(src, "Default", "Preferences"), []byte(`{}`), 0644)
if err := pm.Import("imported-profile", src); err != nil {
t.Fatal(err)
@@ -144,14 +144,14 @@ func TestProfileManagerListReadsLocalStateIdentity(t *testing.T) {
func TestProfileManagerReset(t *testing.T) {
dir := t.TempDir()
pm := NewProfileManager(dir)
- pm.Create("reset-me")
+ _ = pm.Create("reset-me")
sessDir := filepath.Join(dir, "reset-me", "Default", "Sessions")
- os.MkdirAll(sessDir, 0755)
- os.WriteFile(filepath.Join(sessDir, "session1"), []byte("data"), 0644)
+ _ = os.MkdirAll(sessDir, 0755)
+ _ = os.WriteFile(filepath.Join(sessDir, "session1"), []byte("data"), 0644)
cacheDir := filepath.Join(dir, "reset-me", "Default", "Cache")
- os.MkdirAll(cacheDir, 0755)
+ _ = os.MkdirAll(cacheDir, 0755)
if err := pm.Reset("reset-me"); err != nil {
t.Fatal(err)
@@ -180,7 +180,7 @@ func TestProfileManagerResetNotFound(t *testing.T) {
func TestProfileManagerDelete(t *testing.T) {
dir := t.TempDir()
pm := NewProfileManager(dir)
- pm.Create("delete-me")
+ _ = pm.Create("delete-me")
if err := pm.Delete("delete-me"); err != nil {
t.Fatal(err)
@@ -244,8 +244,8 @@ func TestActionTrackerRepeatDetection(t *testing.T) {
func TestProfileHandlerList(t *testing.T) {
pm := NewProfileManager(t.TempDir())
- pm.Create("a")
- pm.Create("b")
+ _ = pm.Create("a")
+ _ = pm.Create("b")
mux := http.NewServeMux()
pm.RegisterHandlers(mux)
@@ -259,7 +259,7 @@ func TestProfileHandlerList(t *testing.T) {
}
var profiles []ProfileInfo
- json.NewDecoder(w.Body).Decode(&profiles)
+ _ = json.NewDecoder(w.Body).Decode(&profiles)
if len(profiles) != 2 {
t.Errorf("expected 2 profiles, got %d", len(profiles))
}
@@ -282,7 +282,7 @@ func TestProfileHandlerCreate(t *testing.T) {
func TestProfileHandlerReset(t *testing.T) {
pm := NewProfileManager(t.TempDir())
- pm.Create("resettable")
+ _ = pm.Create("resettable")
mux := http.NewServeMux()
pm.RegisterHandlers(mux)
@@ -297,7 +297,7 @@ func TestProfileHandlerReset(t *testing.T) {
func TestProfileHandlerDelete(t *testing.T) {
pm := NewProfileManager(t.TempDir())
- pm.Create("deletable")
+ _ = pm.Create("deletable")
mux := http.NewServeMux()
pm.RegisterHandlers(mux)
diff --git a/proxy_ws.go b/proxy_ws.go
index 31505270..5c733783 100644
--- a/proxy_ws.go
+++ b/proxy_ws.go
@@ -28,7 +28,7 @@ func proxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
slog.Error("ws proxy: backend dial failed", "target", host, "err", err)
return
}
- defer backend.Close()
+ defer func() { _ = backend.Close() }()
hj, ok := w.(http.Hijacker)
if !ok {
@@ -40,20 +40,20 @@ func proxyWebSocket(w http.ResponseWriter, r *http.Request, targetURL string) {
slog.Error("ws proxy: hijack failed", "err", err)
return
}
- defer client.Close()
+ defer func() { _ = client.Close() }()
reqLine := r.Method + " " + path + " HTTP/1.1\r\n"
- backend.Write([]byte(reqLine))
- backend.Write([]byte("Host: " + host + "\r\n"))
+ _, _ = backend.Write([]byte(reqLine))
+ _, _ = backend.Write([]byte("Host: " + host + "\r\n"))
for k, vv := range r.Header {
for _, v := range vv {
- backend.Write([]byte(k + ": " + v + "\r\n"))
+ _, _ = backend.Write([]byte(k + ": " + v + "\r\n"))
}
}
- backend.Write([]byte("\r\n"))
+ _, _ = backend.Write([]byte("\r\n"))
done := make(chan struct{}, 2)
- go func() { io.Copy(client, backend); done <- struct{}{} }()
- go func() { io.Copy(backend, client); done <- struct{}{} }()
+ go func() { _, _ = io.Copy(client, backend); done <- struct{}{} }()
+ go func() { _, _ = io.Copy(backend, client); done <- struct{}{} }()
<-done
}
diff --git a/screencast.go b/screencast.go
index 97a01edc..99234ff3 100644
--- a/screencast.go
+++ b/screencast.go
@@ -58,7 +58,7 @@ func (b *Bridge) handleScreencast(w http.ResponseWriter, r *http.Request) {
slog.Error("ws upgrade failed", "err", err)
return
}
- defer conn.Close()
+ defer func() { _ = conn.Close() }()
ctx := tab.ctx
if ctx == nil {