Skip to content

Catch os... errors #320

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

Merged
merged 1 commit into from
Dec 2, 2016
Merged

Catch os... errors #320

merged 1 commit into from
Dec 2, 2016

Conversation

Bwko
Copy link
Member

@Bwko Bwko commented Nov 30, 2016

No description provided.

@@ -79,7 +79,10 @@ func runDump(ctx *cli.Context) error {
log.Printf("Packing dump files...")
z, err := zip.Create(fileName)
if err != nil {
os.Remove(fileName)
osErr := os.Remove(fileName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should keep ignoring this error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ := os.Remove(fileName) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a dump question... Why is it deleting a file it can't create in the first place? :trollface:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe zip.Create might fail some some after file creation?

@@ -102,7 +105,10 @@ func runDump(ctx *cli.Context) error {
}
// FIXME: SSH key file.
if err = z.Close(); err != nil {
os.Remove(fileName)
osErr := os.Remove(fileName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -13,6 +13,8 @@ import (
"strings"
"time"

goLog "log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we already have a logger here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modules/log, not sure which one to use in this case...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^


osErr := os.Remove(listenAddr)
if osErr != nil {
osLog.Fatalf("Fail to remove unix socket directory %s: %v", listenAddr, osErr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use the already available logger?

@@ -37,5 +38,7 @@ func main() {
cmd.CmdAdmin,
}
app.Flags = append(app.Flags, []cli.Flag{}...)
app.Run(os.Args)
err := app.Run(os.Args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I'm wrapping this directly into println

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tboerger Don't do that. Last time, it results in a bug I spent many time to fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now it's not a big difference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not using any logger, it's only printing to stdout. So we will have the same bug again

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, don't output anything to stdout when git via ssh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lunny how do you want me to fix this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lunny cmd/serve.go always returns nil, so this isn't really an issue here :)

file := path.Join(pr.BaseRepo.RepoPath(), headFile)
err = os.Remove(file)
if err != nil {
return fmt.Errorf("Fail to removee dir %s: %v", path.Join(pr.BaseRepo.RepoPath(), headFile), err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this 😆

os.Chdir(workDir)
osErr := os.Chdir(workDir)
if osErr != nil {
goLog.Fatalf("Fail to change directory %s: %v", workDir, osErr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing server-internal dirs to any random client?! 😱

@bkcsoft
Copy link
Member

bkcsoft commented Dec 1, 2016

Overall, change the format to this instead whenever possible. Keeps errors(variables) bound to their context(block).

if err := os.Remove(...); err != nil {
  [...]
}

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 1, 2016
@@ -8,6 +8,7 @@ import (
"crypto/tls"
"fmt"
"io/ioutil"
osLog "log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -37,5 +38,7 @@ func main() {
cmd.CmdAdmin,
}
app.Flags = append(app.Flags, []cli.Flag{}...)
app.Run(os.Args)
err := app.Run(os.Args)
fmt.Printf("Fail to run app with %s: %v", os.Args, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil

@@ -6,6 +6,7 @@ package log

import (
"fmt"
"log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module/log

@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
osLog "log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@Bwko Bwko force-pushed the Errcheck branch 6 times, most recently from 8fa7687 to 0ebf310 Compare December 1, 2016 20:33
@Bwko
Copy link
Member Author

Bwko commented Dec 1, 2016

I've updated my PR.

@lunny
Copy link
Member

lunny commented Dec 2, 2016

LGTM

@lunny lunny added this to the 1.0.0 milestone Dec 2, 2016
@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 2, 2016
@bkcsoft
Copy link
Member

bkcsoft commented Dec 2, 2016

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 2, 2016
@bkcsoft bkcsoft merged commit 4ff0db0 into go-gitea:master Dec 2, 2016
@Bwko Bwko deleted the Errcheck branch December 2, 2016 11:31
@tboerger tboerger added the type/enhancement An improvement of existing functionality label Dec 2, 2016
@tboerger
Copy link
Member

tboerger commented Dec 2, 2016

This partially solves #257

Bwko added a commit to Bwko/gitea that referenced this pull request Dec 3, 2016
Suppress the error when we're removing a file that may not exist
andreynering added a commit that referenced this pull request Dec 3, 2016
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants