Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit f3aae9b

Browse files
高山高山
高山
authored and
高山
committed
修复错误信息没有展示完全
1 parent dcd906b commit f3aae9b

File tree

8 files changed

+30
-12
lines changed

8 files changed

+30
-12
lines changed

src/github.com/gaoyue1989/sshexec/session.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ExecResult struct {
3737
StartTime time.Time
3838
EndTime time.Time
3939
Error error
40+
ErrorInfo string
4041
}
4142

4243
// execute the command and return a result structure
@@ -53,12 +54,16 @@ func (exec *HostSession) Exec(id int, command string, config ssh.ClientConfig) *
5354

5455
if err != nil {
5556
result.Error = err
57+
result.ErrorInfo=err.Error()
58+
result.Result = "ssh连接出错,请检查key信任或ip是否正确"
5659
return result
5760
}
5861

5962
session, err := client.NewSession()
6063

6164
if err != nil {
65+
result.ErrorInfo=err.Error()
66+
result.Result = "ssh连接出错,请检查key信任或ip是否正确"
6267
result.Error = err
6368
return result
6469
}
@@ -73,7 +78,8 @@ func (exec *HostSession) Exec(id int, command string, config ssh.ClientConfig) *
7378
start := time.Now()
7479
if err := session.Run(command); err != nil {
7580
result.Error = err
76-
result.Result = b1.String()
81+
result.ErrorInfo=err.Error()
82+
result.Result = b1.String() +" 错误信息:"+err.Error()
7783
return result
7884
}
7985
end := time.Now()
@@ -98,13 +104,17 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
98104
client, err := ssh.Dial("tcp", exec.Hostname+":"+strconv.Itoa(exec.Port), &config)
99105

100106
if err != nil {
107+
result.ErrorInfo=err.Error()
108+
result.Result = "ssh连接出错,请检查key信任或ip是否正确"
101109
result.Error = err
102110
return result
103111
}
104112

105113
session, err := client.NewSession()
106114

107115
if err != nil {
116+
result.ErrorInfo=err.Error()
117+
result.Result = "ssh连接出错,请检查key信任或ip是否正确"
108118
result.Error = err
109119
return result
110120
}
@@ -120,6 +130,8 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
120130
}
121131
srcFile, err := os.Open(localFilePath)
122132
if err != nil {
133+
result.ErrorInfo=err.Error()
134+
result.Result = err.Error()
123135
result.Error = err
124136
return result
125137
}
@@ -130,13 +142,17 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
130142
// 这里换成实际的 SSH 连接的 用户名,密码,主机名或IP,SSH端口
131143
// create sftp client
132144
if err != nil {
145+
result.ErrorInfo=err.Error()
146+
result.Result = err.Error()
133147
result.Error = err
134148
return result
135149
}
136150
defer sftpClient.Close()
137151

138152
dstFile, err := sftpClient.Create(remoteFilePath)
139153
if err != nil {
154+
result.ErrorInfo=err.Error()
155+
result.Result = err.Error()
140156
result.Error = err
141157
return result
142158
}
@@ -145,12 +161,16 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
145161
//n, err := Copy(dstFile, io.LimitReader(srcFile, fileSize))
146162
n, err := io.Copy(dstFile, io.LimitReader(srcFile, fileSize))
147163
if err != nil {
164+
result.ErrorInfo=err.Error()
165+
result.Result = err.Error()
148166
result.Error = err
149167
return result
150168
}
151169
if n != fileSize {
152170
beego.Info(err)
153171
result.Error = errors.New(fmt.Sprintf("copy: expected %v bytes, got %d", fileSize, n))
172+
result.ErrorInfo=result.Error.Error()
173+
result.Result = result.Error.Error()
154174
return result
155175
}
156176
end := time.Now()

src/library/components/folder.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (c *BaseComponents) CopyFiles() error {
5353
} else {
5454
_, err := c.copyFilesBySftp(src, dest, c.GetHosts())
5555
if err != nil {
56-
beego.Info("11111111111")
5756
beego.Info(err)
5857
return err
5958
}

src/library/ssh/mainfunc.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ func LocalExec(cmd string) sshexec.ExecResult {
4242
execResult.StartTime = time.Now()
4343
execResult.Command = cmd
4444
execCommand := exec.Command("/bin/bash", "-c", cmd)
45-
4645
var b bytes.Buffer
47-
4846
execCommand.Stdout = &b
4947
var b1 bytes.Buffer
5048
execCommand.Stderr = &b1
5149
err := execCommand.Run()
5250
if err != nil {
5351
execResult.Error = err
52+
execResult.ErrorInfo=err.Error()
5453
execResult.Result = b1.String()
5554
return execResult
5655
} else {

src/static/js/5d893d28.js

-1
This file was deleted.

src/static/js/2c224979.js src/static/js/6a3e20e0.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/static/js/97970965.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/views/index.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8"><title>自动发布系统</title><meta name=Keywords content=自动发布系统><meta name=Description content=自动发布系统><meta http-equiv=X-UA-Compatible content="IE=Edge,chrome=1"><link rel="shortcut icon" href=/favicon.ico><link href=/static/css/d9b825ef.css rel=stylesheet></head><body><mainbody></mainbody><script type=text/javascript src=/static/js/2c224979.js></script><script type=text/javascript src=/static/js/90175b91.js></script><script type=text/javascript src=/static/js/5d893d28.js></script></body></html>
1+
<!DOCTYPE html><html><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8"><title>自动发布系统</title><meta name=Keywords content=自动发布系统><meta name=Description content=自动发布系统><meta http-equiv=X-UA-Compatible content="IE=Edge,chrome=1"><link rel="shortcut icon" href=/favicon.ico><link href=/static/css/d9b825ef.css rel=stylesheet></head><body><mainbody></mainbody><script type=text/javascript src=/static/js/6a3e20e0.js></script><script type=text/javascript src=/static/js/90175b91.js></script><script type=text/javascript src=/static/js/97970965.js></script></body></html>

vue-gopub/src/components/terminal/index.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@
8888
for(var j=0;j<text.length;j++){
8989
try{
9090
this.showText.push({text: "IP:"+text[j].Host, "color": color})
91-
if(text[j].Error) {
91+
if(text[j].ErrorInfo) {
9292
this.showText.push({text: "错误结果:\n" + text[j].Result, "color": color})
9393
}else{
9494
this.showText.push({text: "执行结果:\n" + text[j].Result, "color": color})
9595
}
96-
if(text[j].Error){
97-
this.showText.push({text: "错误:"+text[j].Error, "color": color})
96+
if(text[j].ErrorInfo){
97+
this.showText.push({text: "错误:"+text[j].ErrorInfo, "color": color})
9898
}
9999
this.showText.push({text: "=============", "color": color})
100100
}catch (e){
@@ -103,8 +103,8 @@
103103
//this.showText.push({text: this.formatJson(text), "color": color})
104104
}else{
105105
this.showText.push({text: "执行结果:\n"+text.Result, "color": color})
106-
if(text.Error){
107-
this.showText.push({text: "错误:"+text.Error, "color": color})
106+
if(text.ErrorInfo){
107+
this.showText.push({text: "错误:"+text.ErrorInfo, "color": color})
108108
}
109109
this.showText.push({text: "=============", "color": color})
110110
// this.showText.push({text: this.formatJson(text), "color": color})

0 commit comments

Comments
 (0)