Skip to content

Commit

Permalink
Another pass on fixing errors with in juju
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRichardson committed Feb 10, 2021
1 parent dd0f82c commit c36d35b
Show file tree
Hide file tree
Showing 100 changed files with 202 additions and 200 deletions.
2 changes: 1 addition & 1 deletion apiserver/common/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewMultiNotifyWatcher(w ...state.NotifyWatcher) *MultiNotifyWatcher {
<-w.Changes()
go func(wCopy state.NotifyWatcher) {
defer wg.Done()
wCopy.Wait()
_ = wCopy.Wait()
}(w)
// Copy events from the watcher to the staging channel.
go copyEvents(staging, w.Changes(), &m.tomb)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func singletonCode(err error) (string, bool) {
// that by catching the panic if we try to look up
// a non-hashable type.
defer func() {
recover()
_ = recover()
}()
code, ok := singletonErrorCodes[err]
return code, ok
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func getAllUnits(st *state.State, tag names.Tag) ([]string, error) {
}
// Start a watcher on machine's units, read the initial event and stop it.
watch := machine.WatchUnits()
defer watch.Stop()
defer func() { _ = watch.Stop() }()
if units, ok := <-watch.Changes(); ok {
return units, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (s *StorageProvisionerAPIv3) WatchVolumeAttachmentPlans(args params.Entitie
if stringChanges, ok := <-w.Changes(); ok {
changes, err := storagecommon.ParseVolumeAttachmentIds(stringChanges)
if err != nil {
w.Stop()
_ = w.Stop()
return "", nil, err
}
return s.resources.Register(w), changes, nil
Expand Down Expand Up @@ -514,7 +514,7 @@ func (s *StorageProvisionerAPIv3) watchAttachments(
if stringChanges, ok := <-w.Changes(); ok {
changes, err := parseAttachmentIds(stringChanges)
if err != nil {
w.Stop()
_ = w.Stop()
return "", nil, err
}
return s.resources.Register(w), changes, nil
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/application/charmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func openCSClient(args OpenCSRepoParams) (*csclient.Client, error) {
// as a cookie in the HTTP client.
// TODO(cmars) discharge any third party caveats in the macaroon.
ms := []*macaroon.Macaroon{args.CharmStoreMacaroon}
httpbakery.SetCookie(csParams.BakeryClient.Jar, csURL, charmstore.MacaroonNamespace, ms)
_ = httpbakery.SetCookie(csParams.BakeryClient.Jar, csURL, charmstore.MacaroonNamespace, ms)
}
csClient := csclient.New(csParams)
channel := csparams.Channel(args.Channel)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/client/backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@ func MetadataFromResult(result params.BackupsMetadataResult) *backups.Metadata {
MachineInstanceID: result.ControllerMachineInstanceID,
HANodes: result.HANodes,
}
meta.SetFileInfo(result.Size, result.Checksum, result.ChecksumFormat)
_ = meta.SetFileInfo(result.Size, result.Checksum, result.ChecksumFormat)
return meta
}
2 changes: 1 addition & 1 deletion apiserver/facades/client/backups/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (a *API) Restore(p params.RestoreArgs) error {
}
// Any abnormal termination of this function will mark restore as failed,
// successful termination will call Exit and never run this.
defer info.SetStatus(state.RestoreFailed)
defer func() { _ = info.SetStatus(state.RestoreFailed) }()

instanceId, err := machine.InstanceId()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (api *CrossModelRelationsAPI) WatchRelationsSuspendedStatus(
if err != nil {
results.Results[i].Error = apiservererrors.ServerError(err)
changesParams = nil
w.Stop()
_ = w.Stop()
break
}
changesParams[j] = *change
Expand Down Expand Up @@ -593,7 +593,7 @@ func (api *CrossModelRelationsAPI) WatchOfferStatus(
change, err := commoncrossmodel.GetOfferStatusChange(api.model, api.st, arg.OfferUUID, w.OfferName())
if err != nil {
results.Results[i].Error = apiservererrors.ServerError(err)
w.Stop()
_ = w.Stop()
break
}
results.Results[i].Changes = []params.OfferStatusChange{*change}
Expand Down
2 changes: 1 addition & 1 deletion apiserver/logsink/logsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (h *logSinkHandler) receiveLogs(socket *websocket.Conn,
// If the remote end does not support ping/pong, we bump
// the read deadline everytime a message is received.
if endpointVersion == 0 {
socket.SetReadDeadline(time.Now().Add(vZeroDelay))
_ = socket.SetReadDeadline(time.Now().Add(vZeroDelay))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions apiserver/stateauthenticator/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (h *localLoginHandlers) AddLegacyHandlers(mux *apiserverhttp.Mux, discharge
localUserIdentityLocationPath+"/wait",
makeHandler(h.serveWait),
)
mux.AddHandler("GET", localUserIdentityLocationPath+"/wait", dischargeMux)
mux.AddHandler("GET", localUserIdentityLocationPath+"/login", dischargeMux)
mux.AddHandler("POST", localUserIdentityLocationPath+"/login", dischargeMux)
_ = mux.AddHandler("GET", localUserIdentityLocationPath+"/wait", dischargeMux)
_ = mux.AddHandler("GET", localUserIdentityLocationPath+"/login", dischargeMux)
_ = mux.AddHandler("POST", localUserIdentityLocationPath+"/login", dischargeMux)
}

func (h *localLoginHandlers) serveLogin(response http.ResponseWriter, req *http.Request) (interface{}, error) {
Expand Down
8 changes: 4 additions & 4 deletions apiserver/stateauthenticator/locallogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (h *localLoginHandlers) AddHandlers(mux *apiserverhttp.Mux) {
localUserIdentityLocationPath+formURL,
http.HandlerFunc(h.formHandler),
)
mux.AddHandler("POST", localUserIdentityLocationPath+"/discharge", dischargeMux)
mux.AddHandler("GET", localUserIdentityLocationPath+"/publickey", dischargeMux)
mux.AddHandler("GET", localUserIdentityLocationPath+"/form", dischargeMux)
mux.AddHandler("POST", localUserIdentityLocationPath+"/form", dischargeMux)
_ = mux.AddHandler("POST", localUserIdentityLocationPath+"/discharge", dischargeMux)
_ = mux.AddHandler("GET", localUserIdentityLocationPath+"/publickey", dischargeMux)
_ = mux.AddHandler("GET", localUserIdentityLocationPath+"/form", dischargeMux)
_ = mux.AddHandler("POST", localUserIdentityLocationPath+"/form", dischargeMux)

h.AddLegacyHandlers(mux, dischargeMux)
}
Expand Down
5 changes: 2 additions & 3 deletions apiserver/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func (conn *Conn) SendInitialErrorV0(err error) error {

body, err := json.Marshal(wrapped)
if err != nil {
errors.Annotatef(err, "cannot marshal error %#v", wrapped)
return err
return errors.Annotatef(err, "cannot marshal error %#v", wrapped)
}
body = append(body, '\n')

Expand All @@ -83,7 +82,7 @@ func (conn *Conn) SendInitialErrorV0(err error) error {

if wrapped.Error != nil {
// Tell the other end we are closing.
conn.WriteMessage(websocket.CloseMessage, []byte{})
_ = conn.WriteMessage(websocket.CloseMessage, []byte{})
}

return errors.Trace(err)
Expand Down
6 changes: 3 additions & 3 deletions charmstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (c Client) GetResource(req ResourceRequest) (data ResourceData, err error)
if err := c.jar.Activate(req.Charm); err != nil {
return ResourceData{}, errors.Trace(err)
}
defer c.jar.Deactivate()
defer func() { _ = c.jar.Deactivate() }()
meta, err := c.csWrapper.ResourceMeta(req.Channel, req.Charm, req.Name, req.Revision)

if err != nil {
Expand Down Expand Up @@ -238,7 +238,7 @@ func (c Client) ResourceInfo(req ResourceRequest) (resource.Resource, error) {
if err := c.jar.Activate(req.Charm); err != nil {
return resource.Resource{}, errors.Trace(err)
}
defer c.jar.Deactivate()
defer func() { _ = c.jar.Deactivate() }()
meta, err := c.csWrapper.ResourceMeta(req.Channel, req.Charm, req.Name, req.Revision)
if err != nil {
return resource.Resource{}, errors.Trace(err)
Expand Down Expand Up @@ -272,7 +272,7 @@ func (c Client) listResources(ch CharmID) ([]resource.Resource, error) {
if err := c.jar.Activate(ch.URL); err != nil {
return nil, errors.Trace(err)
}
defer c.jar.Deactivate()
defer func() { _ = c.jar.Deactivate() }()
resources, err := c.csWrapper.ListResources(ch.Channel, ch.URL)
if err != nil {
return nil, errors.Trace(err)
Expand Down
2 changes: 1 addition & 1 deletion charmstore/jar.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (j *macaroonJar) Activate(cURL *charm.URL) error {
return errors.Trace(err)
}
if m != nil {
httpbakery.SetCookie(j.underlying, j.serverURL, MacaroonNamespace, m)
_ = httpbakery.SetCookie(j.underlying, j.serverURL, MacaroonNamespace, m)
}
return nil
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/juju/backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *CommandBase) NewAPIClient() (APIClient, error) {
return newAPIClient(c)
}

// NewAPIClient returns a client for the backups api endpoint.
// NewGetAPI returns a client for the backups api endpoint.
func (c *CommandBase) NewGetAPI() (APIClient, int, error) {
return getAPI(c)
}
Expand All @@ -76,7 +76,9 @@ func (c *CommandBase) SetFlags(f *gnuflag.FlagSet) {

// Init implements Command.SetFlags.
func (c *CommandBase) Init(args []string) error {
c.ModelCommandBase.Init(args)
if err := c.ModelCommandBase.Init(args); err != nil {
return errors.Trace(err)
}
c.fs.Visit(func(flag *gnuflag.Flag) {
if flag.Name == "verbose" {
c.verbose = true
Expand Down Expand Up @@ -185,7 +187,7 @@ func (c *CommandBase) metadata(result *params.BackupsMetadataResult) string {
}
t := template.Must(template.New("template").Parse(backupMetadataTemplate))
content := bytes.Buffer{}
t.Execute(&content, m)
_ = t.Execute(&content, m)
return content.String()
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/charmhub/infowriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (iw infoWriter) writeOpenChanneltoBuffer(w *UnicodeWriter, channel Channel)
func (iw infoWriter) writeClosedChannelToBuffer(w *UnicodeWriter, name string, hasOpenChannel bool) {
w.Printf("%s:", name)
if hasOpenChannel {
w.PrintlnUnicode(UnicodeUpArrow)
_, _ = w.PrintlnUnicode(UnicodeUpArrow)
return
}
w.PrintlnUnicode(UnicodeDash)
_, _ = w.PrintlnUnicode(UnicodeDash)
}

type bundleInfoOutput struct {
Expand Down
6 changes: 3 additions & 3 deletions cmd/juju/commands/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ func (c *execCommand) Run(ctx *cmd.Context) error {
if c.compat {
codeKey = "ReturnCode"
}
ctx.Stdout.Write(formatOutput(result, stdoutKey, c.compat))
ctx.Stderr.Write(formatOutput(result, stderrKey, c.compat))
_, _ = ctx.Stdout.Write(formatOutput(result, stdoutKey, c.compat))
_, _ = ctx.Stderr.Write(formatOutput(result, stderrKey, c.compat))
if code, ok := result[codeKey].(int); ok && code != 0 {
return cmd.NewRcPassthroughError(code)
}
Expand All @@ -421,7 +421,7 @@ func (c *execCommand) Run(ctx *cmd.Context) error {
messageKey = "Message"
}
if res, ok := result[messageKey].(string); ok && res != "" {
ctx.Stderr.Write([]byte(res))
_, _ = ctx.Stderr.Write([]byte(res))
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/commands/helptool.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (c *helpToolCommand) Run(ctx *cmd.Context) error {
info := c.Info()
f := gnuflag.NewFlagSetWithFlagKnownAs(info.Name, gnuflag.ContinueOnError, cmd.FlagAlias(c, "option"))
c.SetFlags(f)
ctx.Stdout.Write(info.Help(f))
_, _ = ctx.Stdout.Write(info.Help(f))
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/commands/ssh_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (c *sshMachine) generateKnownHosts(targets []*resolvedTarget) (string, erro
}
defer f.Close()
c.knownHostsPath = f.Name() // Record for later deletion
if knownHosts.write(f); err != nil {
if err := knownHosts.write(f); err != nil {
return "", errors.Trace(err)
}
return c.knownHostsPath, nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/commands/synctools.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (c *syncToolsCommand) Run(ctx *cmd.Context) (resultErr error) {
writer := loggo.NewMinimumLevelWriter(
cmd.NewCommandLogWriter("juju.environs.sync", ctx.Stdout, ctx.Stderr),
loggo.INFO)
loggo.RegisterWriter("syncagentbinaries", writer)
defer loggo.RemoveWriter("syncagentbinaries")
_ = loggo.RegisterWriter("syncagentbinaries", writer)
defer func() { _, _ = loggo.RemoveWriter("syncagentbinaries") }()

sctx := &sync.SyncContext{
AllVersions: c.allVersions,
Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/status/output_tabular.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ func FormatTabular(writer io.Writer, forceColor bool, value interface{}) error {
}

if fs.Storage != nil {
storage.FormatStorageListForStatusTabular(tw, *fs.Storage)
_ = storage.FormatStorageListForStatusTabular(tw, *fs.Storage)
}

endSection(tw)
return nil
}

func startSection(tw *ansiterm.TabWriter, top bool, headers ...interface{}) output.Wrapper {
w := output.Wrapper{tw}
w := output.Wrapper{TabWriter: tw}
if !top {
w.Println()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/jujud/agent/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func StartIntrospection(cfg IntrospectionConfig) error {
return errors.Trace(err)
}
go func() {
cfg.Engine.Wait()
_ = cfg.Engine.Wait()
logger.Debugf("engine stopped, stopping introspection")
w.Kill()
w.Wait()
_ = w.Wait()
logger.Debugf("introspection stopped")
}()

Expand Down
4 changes: 2 additions & 2 deletions cmd/jujud/agent/caasoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (op *CaasOperatorAgent) Run(ctx *cmd.Context) (err error) {
logger.Warningf("developer feature flags enabled: %s", flags)
}

op.runner.StartWorker("api", op.Workers)
_ = op.runner.StartWorker("api", op.Workers)
return cmdutil.AgentDone(logger, op.runner.Wait())
}

Expand All @@ -221,7 +221,7 @@ func (op *CaasOperatorAgent) Workers() (worker.Worker, error) {

agentConfig := op.AgentConf.CurrentConfig()
manifoldConfig := caasoperator.ManifoldsConfig{
Agent: agent.APIHostPortsSetter{op},
Agent: agent.APIHostPortsSetter{Agent: op},
AgentConfigChanged: op.configChangedVal,
Clock: clock.WallClock,
LogSource: op.bufferedLogger.Logs(),
Expand Down
6 changes: 3 additions & 3 deletions cmd/jujud/agent/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (a *machineAgentCmd) Init(args []string) error {
// models that have been upgraded, we need to explicitly remove the
// file writer if one has been added, otherwise we will get duplicate
// lines of all logging in the log file.
loggo.RemoveWriter("logfile")
_, _ = loggo.RemoveWriter("logfile")

if a.machineId != "" {
a.agentTag = names.NewMachineTag(a.machineId)
Expand Down Expand Up @@ -507,7 +507,7 @@ func (a *MachineAgent) Run(ctx *cmd.Context) (err error) {
if err := a.createJujudSymlinks(agentConfig.DataDir()); err != nil {
return err
}
a.runner.StartWorker("engine", createEngine)
_ = a.runner.StartWorker("engine", createEngine)

// At this point, all workers will have been configured to start
close(a.workersStarted)
Expand Down Expand Up @@ -730,7 +730,7 @@ func (a *MachineAgent) startAPIWorkers(apiConn api.Connection) (_ worker.Worker,
}
}
if !isController {
runner.StartWorker("stateconverter", func() (worker.Worker, error) {
_ = runner.StartWorker("stateconverter", func() (worker.Worker, error) {
// TODO(fwereade): this worker needs its own facade.
facade := apimachiner.NewState(apiConn)
handler := conv2state.New(facade, a)
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/agent/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (m *ModelCommand) Run(ctx *cmd.Context) error {

m.upgradeComplete = upgradesteps.NewLock(m.CurrentConfig())

m.runner.StartWorker("modeloperator", m.Workers)
_ = m.runner.StartWorker("modeloperator", m.Workers)
return cmdutil.AgentDone(logger, m.runner.Wait())
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/jujud/agent/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (a *UnitAgent) Run(ctx *cmd.Context) (err error) {
}
agentconf.SetupAgentLogging(loggo.DefaultContext(), a.CurrentConfig())

a.runner.StartWorker("api", a.APIWorkers)
_ = a.runner.StartWorker("api", a.APIWorkers)
err = cmdutil.AgentDone(logger, a.runner.Wait())
return err
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (a *UnitAgent) APIWorkers() (worker.Worker, error) {
}

manifolds := unitManifolds(unit.ManifoldsConfig{
Agent: agent.APIHostPortsSetter{a},
Agent: agent.APIHostPortsSetter{Agent: a},
LogSource: a.bufferedLogger.Logs(),
LeadershipGuarantee: 30 * time.Second,
AgentConfigChanged: a.configChangedVal,
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/dumplogs/dumplogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *dumpLogsCommand) dumpLogsForEnv(ctx *cmd.Context, statePool *state.Stat
if !ok {
break
}
writer.WriteString(c.format(
_, _ = writer.WriteString(c.format(
rec.Time,
rec.Level,
rec.Entity,
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/introspect/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (c *IntrospectCommand) Run(ctx *cmd.Context) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
io.Copy(ctx.Stderr, resp.Body)
_, _ = io.Copy(ctx.Stderr, resp.Body)
return errors.Errorf(
"response returned %d (%s)",
resp.StatusCode,
Expand Down
Loading

0 comments on commit c36d35b

Please sign in to comment.