-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Catch os... errors #320
Conversation
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ := os.Remove(fileName)
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch :D
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?! 😱
Overall, change the format to this instead whenever possible. Keeps errors(variables) bound to their context(block).
|
@@ -8,6 +8,7 @@ import ( | |||
"crypto/tls" | |||
"fmt" | |||
"io/ioutil" | |||
osLog "log" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
8fa7687
to
0ebf310
Compare
I've updated my PR. |
LGTM |
LGTM |
This partially solves #257 |
Suppress the error when we're removing a file that may not exist
No description provided.