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

Error returned by function calls is not explicitly checked #45

Open
subpop opened this issue Sep 14, 2023 · 0 comments
Open

Error returned by function calls is not explicitly checked #45

subpop opened this issue Sep 14, 2023 · 0 comments

Comments

@subpop
Copy link
Collaborator

subpop commented Sep 14, 2023

Running the package through a static analyzer results in the following findings:

1. rhc/rhc-0.2.4/util.go:129: suppressed_error: The error returned by the function "Parse("redhat_access/r/insights/platform/config-manager/v2/profiles/current")" is not explicitly checked.
2. rhc/rhc-0.2.4/util.go:129: remediation: Explicitly check the return error.
#   127|   				return "", fmt.Errorf("cannot get base URL: %w", err)
#   128|   			}
#   129|-> 			p, _ := url.Parse("redhat_access/r/insights/platform/config-manager/v2/profiles/current")
#   130|   			uString = base.ResolveReference(p).String()
#   131|   		}
1. rhc/rhc-0.2.4/util.go:120: suppressed_error: The error returned by the function "Parse("api/config-manager/v2/profiles/current")" is not explicitly checked.
2. rhc/rhc-0.2.4/util.go:120: remediation: Explicitly check the return error.
#   118|   		if strings.Contains(serverHost, "subscription.rhsm.redhat.com") {
#   119|   			baseURL, _ = url.Parse("https://cert.console.redhat.com")
#   120|-> 			p, _ := url.Parse("api/config-manager/v2/profiles/current")
#   121|   			uString = baseURL.ResolveReference(p).String()
#   122|   		} else {
1. rhc/rhc-0.2.4/util.go:119: suppressed_error: The error returned by the function "Parse("https://cert.console.redhat.com")" is not explicitly checked.
2. rhc/rhc-0.2.4/util.go:119: remediation: Explicitly check the return error.
#   117|   		// Check if it is the default api server
#   118|   		if strings.Contains(serverHost, "subscription.rhsm.redhat.com") {
#   119|-> 			baseURL, _ = url.Parse("https://cert.console.redhat.com")
#   120|   			p, _ := url.Parse("api/config-manager/v2/profiles/current")
#   121|   			uString = baseURL.ResolveReference(p).String()
1. rhc/rhc-0.2.4/util.go:107: suppressed_error: The error returned by the function "Parse("api/config-manager/v2/profiles/current")" is not explicitly checked.
2. rhc/rhc-0.2.4/util.go:107: remediation: Explicitly check the return error.
#   105|   			return "", fmt.Errorf("cannot get base URL: %w", err)
#   106|   		}
#   107|-> 		p, _ := url.Parse("api/config-manager/v2/profiles/current")
#   108|   		uString = base.ResolveReference(p).String()
#   109|   	} else {
1. rhc/rhc-0.2.4/main.go:236: suppressed_error: The error returned by the function "writer.Flush()" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:236: remediation: Explicitly check the return error.
#   234|   						}
#   235|   					}
#   236|-> 					_ = writer.Flush()
#   237|   					fmt.Print("\nOrganization: ")
#   238|   					_ = scanner.Scan()
1. rhc/rhc-0.2.4/main.go:233: suppressed_error: The error returned by the function "Fprint(writer, "\n")" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:233: remediation: Explicitly check the return error.
#   231|   						_, _ = fmt.Fprintf(writer, "%v\t", org)
#   232|   						if (i+1)%4 == 0 {
#   233|-> 							_, _ = fmt.Fprint(writer, "\n")
#   234|   						}
#   235|   					}
1. rhc/rhc-0.2.4/main.go:231: suppressed_error: The error returned by the function "Fprintf(writer, "%v\t", org)" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:231: remediation: Explicitly check the return error.
#   229|   					writer := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
#   230|   					for i, org := range orgs {
#   231|-> 						_, _ = fmt.Fprintf(writer, "%v\t", org)
#   232|   						if (i+1)%4 == 0 {
#   233|   							_, _ = fmt.Fprint(writer, "\n")
1. rhc/rhc-0.2.4/main.go:105: suppressed_error: The error returned by the function "w.Flush()" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:105: remediation: Explicitly check the return error.
#   103|   			}
#   104|   		}
#   105|-> 		_ = w.Flush()
#   106|   		if hasPriorityErrors(errorMessages, log.LevelError) {
#   107|   			return cli.Exit("", 1)
1. rhc/rhc-0.2.4/main.go:102: suppressed_error: The error returned by the function "Fprintf(w, "%v\t%v\t%v\n", logMsg.level, step, logMsg.message)" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:102: remediation: Explicitly check the return error.
#   100|   		for step, logMsg := range errorMessages {
#   101|   			if logMsg.level <= log.CurrentLevel() {
#   102|-> 				_, _ = fmt.Fprintf(w, "%v\t%v\t%v\n", logMsg.level, step, logMsg.message)
#   103|   			}
#   104|   		}
1. rhc/rhc-0.2.4/main.go:99: suppressed_error: The error returned by the function "Fprintln(w, "TYPE\tSTEP\tERROR\t")" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:99: remediation: Explicitly check the return error.
#    97|   		fmt.Printf("The following errors were encountered during %s:\n\n", action)
#    98|   		w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
#    99|-> 		_, _ = fmt.Fprintln(w, "TYPE\tSTEP\tERROR\t")
#   100|   		for step, logMsg := range errorMessages {
#   101|   			if logMsg.level <= log.CurrentLevel() {
1. rhc/rhc-0.2.4/main.go:87: suppressed_error: The error returned by the function "Fprintf(w, "%v\t%v\t\n", step, duration.Truncate(1000000))" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:87: remediation: Explicitly check the return error.
#    85|   		_, _ = fmt.Fprintln(w, "STEP\tDURATION\t")
#    86|   		for step, duration := range durations {
#    87|-> 			_, _ = fmt.Fprintf(w, "%v\t%v\t\n", step, duration.Truncate(time.Millisecond))
#    88|   		}
#    89|   		_ = w.Flush()
1. rhc/rhc-0.2.4/main.go:85: suppressed_error: The error returned by the function "Fprintln(w, "STEP\tDURATION\t")" is not explicitly checked.
2. rhc/rhc-0.2.4/main.go:85: remediation: Explicitly check the return error.
#    83|   		fmt.Println()
#    84|   		w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
#    85|-> 		_, _ = fmt.Fprintln(w, "STEP\tDURATION\t")
#    86|   		for step, duration := range durations {
#    87|   			_, _ = fmt.Fprintf(w, "%v\t%v\t\n", step, duration.Truncate(time.Millisecond))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant