Skip to content

Commit

Permalink
Clean error messages on bad connection
Browse files Browse the repository at this point in the history
fix issue #18
  • Loading branch information
Jay Janssen committed Aug 10, 2015
1 parent bcbd7d6 commit 91ba7d7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions myqlib/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,19 @@ func (l LiveLoader) harvestMySQL(command MySQLCommand) (chan MyqSample, error) {
return nil, err
}

// feed the MYSQLCLI the given command to produce more output
send_command := func() {
_, err := stdin.Write([]byte(command))
// Handle if the subcommand exits
go func() {
err := cmd.Wait()
if err != nil {
panic("Could not write to MySQL command any longer")
os.Stderr.WriteString(stderr.String())
os.Exit(1)
}
}()

// feed the MYSQLCLI the given command to produce more output
send_command := func() {
// We don't check if the write failed, it's assumed the cmd.Wait() above will catch the sub proc dying
stdin.Write([]byte(command))
}
// send the first command immediately
send_command()
Expand All @@ -306,15 +313,6 @@ func (l LiveLoader) harvestMySQL(command MySQLCommand) (chan MyqSample, error) {
parseSamples(stdout, ch, l.loaderInterval.getInterval())
}()

// Handle if the subcommand exits
go func() {
err := cmd.Wait()
if err != nil {
os.Stderr.WriteString(stderr.String())
os.Exit(1)
}
}()

// Got this far, the channel should start getting samples
return ch, nil
}
Expand Down

0 comments on commit 91ba7d7

Please sign in to comment.