Skip to content

Commit 518bebf

Browse files
author
Ubuntu
committed
chore: handle critical errors and ignore minor ones for lint compliance
1 parent e14d041 commit 518bebf

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

cmd/exec.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ func (o *ExecOptions) Run() error {
288288
}
289289

290290
wp.Wait()
291-
configStore.Save(cfg)
291+
if err := configStore.Save(cfg); err != nil {
292+
logger.PrintErrorf("保存配置失败: %v", err)
293+
}
292294
return nil
293295
}
294296

cmd/firewall.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var firewallCmd = &cobra.Command{
4646
Long: `支持多后端 (firewalld, ufw, iptables, nftables) 的防火墙管理工具。
4747
会自动探测目标主机使用的防火墙类型。`,
4848
Run: func(cmd *cobra.Command, args []string) {
49-
cmd.Help()
49+
_ = cmd.Help()
5050
},
5151
}
5252

@@ -90,7 +90,9 @@ func (o *FirewallOptions) RunOnHosts(ctx context.Context, action func(fw firewal
9090
logger.PrintSuccessf("[LOCAL] (%s) Success\n%s", fw.Name(), out)
9191
}
9292
if o.Reload {
93-
fw.Reload(ctx)
93+
if err := fw.Reload(ctx); err != nil {
94+
logger.PrintErrorf("[LOCAL] 重启防火墙失败: %v", err)
95+
}
9496
}
9597
return nil
9698
}
@@ -176,7 +178,9 @@ func (o *FirewallOptions) RunOnHosts(ctx context.Context, action func(fw firewal
176178
}
177179

178180
if o.Reload {
179-
fw.Reload(ctx)
181+
if err := fw.Reload(ctx); err != nil {
182+
logger.PrintErrorf("[%s] 重启防火墙失败: %v", rawHost, err)
183+
}
180184
}
181185
})
182186
}
@@ -186,7 +190,9 @@ func (o *FirewallOptions) RunOnHosts(ctx context.Context, action func(fw firewal
186190
}
187191

188192
wp.Wait()
189-
configStore.Save(cfg)
193+
if err := configStore.Save(cfg); err != nil {
194+
logger.PrintErrorf("保存配置失败: %v", err)
195+
}
190196
return nil
191197
}
192198

cmd/identity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func NewCmdIdentity() *cobra.Command {
2020
Short: "管理认证信息模板",
2121
Long: `管理存储的认证信息模板(用户、密码、私钥)。通过别名可以在添加主机时快速复用。`,
2222
Run: func(cmd *cobra.Command, args []string) {
23-
cmd.Help()
23+
_ = cmd.Help()
2424
},
2525
}
2626

cmd/utils/hosts.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ func ReadCSVFile(path string) ([]HostInfo, error) {
9999
// 如果CSV中有专门的端口列,则覆盖解析出的端口
100100
if pStr := getVal(idxPort); pStr != "" {
101101
var p uint16
102-
fmt.Sscanf(pStr, "%d", &p)
103-
if p != 0 {
102+
if _, err := fmt.Sscanf(pStr, "%d", &p); err == nil && p != 0 {
104103
port = p
105104
}
106105
}

pkg/executor/local.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (e *LocalExecutor) RunWithSudo(ctx context.Context, cmd string) (string, er
5151
}
5252

5353
go func() {
54-
defer stdin.Close()
55-
io.WriteString(stdin, e.password+"\n")
54+
defer func() { _ = stdin.Close() }()
55+
_, _ = io.WriteString(stdin, e.password+"\n")
5656
}()
5757

5858
out, err := c.CombinedOutput()
@@ -90,9 +90,9 @@ func (e *LocalExecutor) InteractiveWithSudo(ctx context.Context, args []string)
9090
return err
9191
}
9292
// 注入密码
93-
stdin.Write([]byte(e.password + "\n"))
93+
_, _ = stdin.Write([]byte(e.password + "\n"))
9494
// 将本地标准输入转发给进程
95-
go io.Copy(stdin, os.Stdin)
95+
go func() { _ = io.Copy(stdin, os.Stdin) }()
9696
return c.Wait()
9797
} else {
9898
// 无密码模式,直接连接标准流

0 commit comments

Comments
 (0)