Skip to content

Commit

Permalink
Skip errors in execotor
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Feb 11, 2024
1 parent fe92da0 commit c28c2e2
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (executor *Executor) Execute(w io.Writer, ses *config.Session, commands ...
}

if i+1 != len(commands) {
fmt.Fprintln(w, CommandsResponseSeparator)
_, _ = fmt.Fprintln(w, CommandsResponseSeparator)
}
}

Expand All @@ -186,18 +186,18 @@ func (executor *Executor) Execute(w io.Writer, ses *config.Session, commands ...
// and prints the responses.
func (executor *Executor) Interactive(r io.Reader, w io.Writer, ses *config.Session) error {
if ses.Address == "" {
fmt.Fprint(w, "Enter remote host and port [ip:port]: ")
fmt.Fscanln(r, &ses.Address)
_, _ = fmt.Fprint(w, "Enter remote host and port [ip:port]: ")
_, _ = fmt.Fscanln(r, &ses.Address)
}

if ses.Password == "" {
fmt.Fprint(w, "Enter password: ")
fmt.Fscanln(r, &ses.Password)
_, _ = fmt.Fprint(w, "Enter password: ")
_, _ = fmt.Fscanln(r, &ses.Password)
}

if ses.Type == "" {
fmt.Fprint(w, "Enter protocol type (empty for rcon): ")
fmt.Fscanln(r, &ses.Type)
_, _ = fmt.Fprint(w, "Enter protocol type (empty for rcon): ")
_, _ = fmt.Fscanln(r, &ses.Type)
}

switch ses.Type {
Expand All @@ -208,7 +208,7 @@ func (executor *Executor) Interactive(r io.Reader, w io.Writer, ses *config.Sess
return err
}

fmt.Fprintf(w, "Waiting commands for %s (or type %s to exit)\n> ", ses.Address, CommandQuit)
_, _ = fmt.Fprintf(w, "Waiting commands for %s (or type %s to exit)\n> ", ses.Address, CommandQuit)

scanner := bufio.NewScanner(r)
for scanner.Scan() {
Expand All @@ -223,10 +223,10 @@ func (executor *Executor) Interactive(r io.Reader, w io.Writer, ses *config.Sess
}
}

fmt.Fprint(w, "> ")
_, _ = fmt.Fprint(w, "> ")
}
default:
fmt.Fprintf(w, "Unsupported protocol type (%q). Allowed %q, %q and %q protocols\n",
_, _ = fmt.Fprintf(w, "Unsupported protocol type (%q). Allowed %q, %q and %q protocols\n",
ses.Type, config.ProtocolRCON, config.ProtocolWebRCON, config.ProtocolTELNET)
}

Expand Down Expand Up @@ -345,19 +345,19 @@ func (executor *Executor) execute(w io.Writer, ses *config.Session, command stri
result, err = executor.client.Execute(command)
if result != "" {
result = strings.TrimSpace(result)
fmt.Fprintln(w, result)
_, _ = fmt.Fprintln(w, result)
}

if err != nil {
if ses.SkipErrors {
fmt.Fprintln(w, fmt.Errorf("execute: %w", err))
_, _ = fmt.Fprintln(w, fmt.Errorf("execute: %w", err))
} else {
return fmt.Errorf("execute: %w", err)
}
}

if err = logger.Write(ses.Log, ses.Address, command, result); err != nil {
fmt.Fprintln(w, fmt.Errorf("log: %w", err))
_, _ = fmt.Fprintln(w, fmt.Errorf("log: %w", err))
}

return nil
Expand Down

0 comments on commit c28c2e2

Please sign in to comment.