Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): make linter happy #97

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CGO_ENABLED ?= 1
#

# It's necessary to set this because some environments don't link sh -> bash.
export SHELL := /bin/bash
export SHELL := bash
Thrimbda marked this conversation as resolved.
Show resolved Hide resolved

# It's necessary to set the errexit flags for the bash shell.
export SHELLOPTS := errexit
Expand All @@ -77,7 +77,7 @@ DOCKER_LABELS ?= git-describe="$(shell date -u +v%Y%m%d)-$(shell git describe --
# Golang standard bin directory.
GOPATH ?= $(shell go env GOPATH)
GOROOT ?= $(shell go env GOROOT)
BIN_DIR := $(GOROOT)/bin
BIN_DIR := $(GOPATH)/bin
gaocegege marked this conversation as resolved.
Show resolved Hide resolved
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint

# Default golang flags used in build and test
Expand Down Expand Up @@ -105,7 +105,7 @@ $(GOLANGCI_LINT):
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(BIN_DIR) v1.23.6

mockgen-install:
go get -u github.com/golang/mock/mockgen
go install github.com/golang/mock/mockgen@v1.6.0
gaocegege marked this conversation as resolved.
Show resolved Hide resolved

build-local:
@for target in $(TARGETS); do \
Expand Down
5 changes: 4 additions & 1 deletion pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func (g generalClient) StartBuildkitd(ctx context.Context,
if err != nil {
return "", errors.Wrap(err, "failed to pull image")
}
io.Copy(os.Stdout, body)
_, err = io.Copy(os.Stdout, body)
if err != nil {
logger.WithError(err).Warningln("failed to copy image pull output")
}
defer body.Close()
} else {
return "", errors.Wrap(err, "failed to inspect image")
Expand Down
8 changes: 6 additions & 2 deletions pkg/lang/frontend/starlark/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func ruleFuncUbuntuAPT(thread *starlark.Thread, _ *starlark.Builtin,

logger.Debugf("rule `%s` is invoked, mode=%s, source=%s", ruleUbuntuAPT,
modeStr, sourceStr)
ir.UbuntuAPT(modeStr, sourceStr)
if err := ir.UbuntuAPT(modeStr, sourceStr); err != nil {
return nil, err
}

return starlark.None, nil
}
Expand All @@ -200,7 +202,9 @@ func ruleFuncPyPIMirror(thread *starlark.Thread, _ *starlark.Builtin,

logger.Debugf("rule `%s` is invoked, mode=%s, mirror=%s", rulePyPIMirror,
modeStr, mirrorStr)
ir.PyPIMirror(modeStr, mirrorStr)
if err := ir.PyPIMirror(modeStr, mirrorStr); err != nil {
return nil, err
}

return starlark.None, nil
}
3 changes: 3 additions & 0 deletions pkg/progress/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (cl consoleLogger) PrintSuccess() {
}

// Printf prints formatted text to the console.
// nolint:errcheck
func (cl consoleLogger) Printf(format string, args ...interface{}) {
cl.mu.Lock()
defer cl.mu.Unlock()
Expand All @@ -103,6 +104,7 @@ func (cl consoleLogger) Printf(format string, args ...interface{}) {
}

// PrintBytes prints bytes directly to the console.
// nolint:errcheck
func (cl consoleLogger) PrintBytes(data []byte) {
// TODO: This does not deal well with control characters, because of the prefix.
cl.mu.Lock()
Expand All @@ -120,6 +122,7 @@ func (cl consoleLogger) PrintBytes(data []byte) {
}
}

// nolint:errcheck
func (cl consoleLogger) printPrefix() {
// Assumes mu locked.
if cl.prefix == "" {
Expand Down
39 changes: 30 additions & 9 deletions pkg/remote/sshd/sshd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ type Server struct {

// ListenAndServe starts the SSH server using port
func (srv *Server) ListenAndServe() error {
server := srv.getServer()
server, err := srv.getServer()
if err != nil {
return errors.Wrap(err, "failed to parse server configs")
}
return server.ListenAndServe()
}

func (srv *Server) getServer() *ssh.Server {
func (srv *Server) getServer() (*ssh.Server, error) {
forwardHandler := &ssh.ForwardedTCPHandler{}

server := &ssh.Server{
Expand All @@ -106,7 +109,10 @@ func (srv *Server) getServer() *ssh.Server {
},
}

server.SetOption(ssh.HostKeyPEM([]byte(hostKeyBytes)))
err := server.SetOption(ssh.HostKeyPEM([]byte(hostKeyBytes)))
if err != nil {
return nil, err
}

if srv.AuthorizedKeys != nil {
server.PublicKeyHandler = srv.authorize
Expand All @@ -115,7 +121,7 @@ func (srv *Server) getServer() *ssh.Server {
server.PasswordHandler = nil
}

return server
return server, nil
}

func (srv Server) buildCmd(logger *logrus.Entry, s ssh.Session) *exec.Cmd {
Expand Down Expand Up @@ -172,7 +178,10 @@ func (srv *Server) connectionHandler(s ssh.Session) {
return
}

s.Exit(0)
err := s.Exit(0)
if err != nil {
logger.Warningln("exit session with error:", err)
}
return
}

Expand All @@ -182,7 +191,10 @@ func (srv *Server) connectionHandler(s ssh.Session) {
return
}

s.Exit(0)
err := s.Exit(0)
if err != nil {
logger.Warningln("exit session with error:", err)
}
}

func handlePTY(logger *logrus.Entry, cmd *exec.Cmd, s ssh.Session, ptyReq ssh.Pty, winCh <-chan ssh.Window) error {
Expand All @@ -203,13 +215,19 @@ func handlePTY(logger *logrus.Entry, cmd *exec.Cmd, s ssh.Session, ptyReq ssh.Pt
}()

go func() {
io.Copy(f, s) // stdin
_, err := io.Copy(f, s) // stdin
if err != nil {
logger.WithError(err).Warningln("failed to copy stdin")
}
}()

waitCh := make(chan struct{})
go func() {
defer close(waitCh)
io.Copy(s, f) // stdout
_, err := io.Copy(s, f) // stdout
if err != nil {
logger.WithError(err).Warningln("failed to copy stdin")
}
}()

if err := cmd.Wait(); err != nil {
Expand All @@ -230,8 +248,11 @@ func handlePTY(logger *logrus.Entry, cmd *exec.Cmd, s ssh.Session, ptyReq ssh.Pt
func setWinsize(f *os.File, w, h int) {
// TODO(gaocegege): Should we use syscall or docker resize?
// Refer to https://github.com/gliderlabs/ssh/blob/master/_examples/ssh-docker/docker.go#L99
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ),
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ),
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0})))
if err != 0 {
logrus.WithError(err).Error("failed to set winsize")
}
}

func sendErrAndExit(logger *logrus.Entry, s ssh.Session, err error) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/unzip/unzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func Unzip(src string, dest string) ([]string, error) {
uid := os.Getuid()
gid := os.Getgid()

ensureDir(dest)
err := ensureDir(dest)
if err != nil {
return filenames, err
}
r, err := zip.OpenReader(src)
if err != nil {
return filenames, err
Expand Down