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

Commit

Permalink
修复错误信息没有展示完全
Browse files Browse the repository at this point in the history
  • Loading branch information
高山 authored and 高山 committed Apr 9, 2018
1 parent dcd906b commit f3aae9b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
22 changes: 21 additions & 1 deletion src/github.com/gaoyue1989/sshexec/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ExecResult struct {
StartTime time.Time
EndTime time.Time
Error error
ErrorInfo string
}

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

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

session, err := client.NewSession()

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

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

session, err := client.NewSession()

if err != nil {
result.ErrorInfo=err.Error()
result.Result = "ssh连接出错,请检查key信任或ip是否正确"
result.Error = err
return result
}
Expand All @@ -120,6 +130,8 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
}
srcFile, err := os.Open(localFilePath)
if err != nil {
result.ErrorInfo=err.Error()
result.Result = err.Error()
result.Error = err
return result
}
Expand All @@ -130,13 +142,17 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
// 这里换成实际的 SSH 连接的 用户名,密码,主机名或IP,SSH端口
// create sftp client
if err != nil {
result.ErrorInfo=err.Error()
result.Result = err.Error()
result.Error = err
return result
}
defer sftpClient.Close()

dstFile, err := sftpClient.Create(remoteFilePath)
if err != nil {
result.ErrorInfo=err.Error()
result.Result = err.Error()
result.Error = err
return result
}
Expand All @@ -145,12 +161,16 @@ func (exec *HostSession) Transfer(id int, localFilePath string, remoteFilePath s
//n, err := Copy(dstFile, io.LimitReader(srcFile, fileSize))
n, err := io.Copy(dstFile, io.LimitReader(srcFile, fileSize))
if err != nil {
result.ErrorInfo=err.Error()
result.Result = err.Error()
result.Error = err
return result
}
if n != fileSize {
beego.Info(err)
result.Error = errors.New(fmt.Sprintf("copy: expected %v bytes, got %d", fileSize, n))
result.ErrorInfo=result.Error.Error()
result.Result = result.Error.Error()
return result
}
end := time.Now()
Expand Down
1 change: 0 additions & 1 deletion src/library/components/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (c *BaseComponents) CopyFiles() error {
} else {
_, err := c.copyFilesBySftp(src, dest, c.GetHosts())
if err != nil {
beego.Info("11111111111")
beego.Info(err)
return err
}
Expand Down
3 changes: 1 addition & 2 deletions src/library/ssh/mainfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ func LocalExec(cmd string) sshexec.ExecResult {
execResult.StartTime = time.Now()
execResult.Command = cmd
execCommand := exec.Command("/bin/bash", "-c", cmd)

var b bytes.Buffer

execCommand.Stdout = &b
var b1 bytes.Buffer
execCommand.Stderr = &b1
err := execCommand.Run()
if err != nil {
execResult.Error = err
execResult.ErrorInfo=err.Error()
execResult.Result = b1.String()
return execResult
} else {
Expand Down
1 change: 0 additions & 1 deletion src/static/js/5d893d28.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/static/js/2c224979.js → src/static/js/6a3e20e0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/static/js/97970965.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/views/index.tpl
Original file line number Diff line number Diff line change
@@ -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>
<!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>
10 changes: 5 additions & 5 deletions vue-gopub/src/components/terminal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
for(var j=0;j<text.length;j++){
try{
this.showText.push({text: "IP:"+text[j].Host, "color": color})
if(text[j].Error) {
if(text[j].ErrorInfo) {
this.showText.push({text: "错误结果:\n" + text[j].Result, "color": color})
}else{
this.showText.push({text: "执行结果:\n" + text[j].Result, "color": color})
}
if(text[j].Error){
this.showText.push({text: "错误:"+text[j].Error, "color": color})
if(text[j].ErrorInfo){
this.showText.push({text: "错误:"+text[j].ErrorInfo, "color": color})
}
this.showText.push({text: "=============", "color": color})
}catch (e){
Expand All @@ -103,8 +103,8 @@
//this.showText.push({text: this.formatJson(text), "color": color})
}else{
this.showText.push({text: "执行结果:\n"+text.Result, "color": color})
if(text.Error){
this.showText.push({text: "错误:"+text.Error, "color": color})
if(text.ErrorInfo){
this.showText.push({text: "错误:"+text.ErrorInfo, "color": color})
}
this.showText.push({text: "=============", "color": color})
// this.showText.push({text: this.formatJson(text), "color": color})
Expand Down

0 comments on commit f3aae9b

Please sign in to comment.