Split off error MOTD error logging

The error logging in outputDefaultTFCLoginSuccess() is an unrelated side
effect.
This commit is contained in:
Chris Arcand 2021-04-22 08:55:59 -05:00
parent 4b97411890
commit 58ec68063b
1 changed files with 15 additions and 7 deletions

View File

@ -237,13 +237,15 @@ func (c *LoginCommand) Run(args []string) int {
motdServiceURL, err := host.ServiceURL("motd.v1") motdServiceURL, err := host.ServiceURL("motd.v1")
if err != nil { if err != nil {
c.outputDefaultTFCLoginSuccess(err) c.logMOTDError(err)
c.outputDefaultTFCLoginSuccess()
return 0 return 0
} }
req, err := http.NewRequest("GET", motdServiceURL.String(), nil) req, err := http.NewRequest("GET", motdServiceURL.String(), nil)
if err != nil { if err != nil {
c.outputDefaultTFCLoginSuccess(err) c.logMOTDError(err)
c.outputDefaultTFCLoginSuccess()
return 0 return 0
} }
@ -251,13 +253,15 @@ func (c *LoginCommand) Run(args []string) int {
resp, err := httpclient.New().Do(req) resp, err := httpclient.New().Do(req)
if err != nil { if err != nil {
c.outputDefaultTFCLoginSuccess(err) c.logMOTDError(err)
c.outputDefaultTFCLoginSuccess()
return 0 return 0
} }
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
c.outputDefaultTFCLoginSuccess(err) c.logMOTDError(err)
c.outputDefaultTFCLoginSuccess()
return 0 return 0
} }
@ -270,7 +274,8 @@ func (c *LoginCommand) Run(args []string) int {
) )
return 0 return 0
} else { } else {
c.outputDefaultTFCLoginSuccess(fmt.Errorf("platform responded with errors or an empty message")) c.logMOTDError(fmt.Errorf("platform responded with errors or an empty message"))
c.outputDefaultTFCLoginSuccess()
return 0 return 0
} }
} }
@ -305,8 +310,7 @@ func (c *LoginCommand) outputDefaultTFELoginSuccess(dispHostname string) {
) )
} }
func (c *LoginCommand) outputDefaultTFCLoginSuccess(err error) { func (c *LoginCommand) outputDefaultTFCLoginSuccess() {
log.Printf("[TRACE] login: An error occurred attempting to fetch a message of the day for Terraform Cloud: %s", err)
c.Ui.Output( c.Ui.Output(
fmt.Sprintf( fmt.Sprintf(
c.Colorize().Color(strings.TrimSpace(` c.Colorize().Color(strings.TrimSpace(`
@ -316,6 +320,10 @@ func (c *LoginCommand) outputDefaultTFCLoginSuccess(err error) {
) )
} }
func (c *LoginCommand) logMOTDError(err error) {
log.Printf("[TRACE] login: An error occurred attempting to fetch a message of the day for Terraform Cloud: %s", err)
}
// Help implements cli.Command. // Help implements cli.Command.
func (c *LoginCommand) Help() string { func (c *LoginCommand) Help() string {
defaultFile := c.defaultOutputFile() defaultFile := c.defaultOutputFile()