Skip to content

Commit

Permalink
🐡 cmd: print startup errors to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Apr 9, 2024
1 parent 203e779 commit 4fbdbab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions cmd/shadowsocks-go-domain-set-converter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,56 +54,56 @@ func main() {
}

if inCount != 1 {
fmt.Println("Exactly one of -inDlc, -inText, -inGob must be specified.")
fmt.Fprintln(os.Stderr, "Exactly one of -inDlc, -inText, -inGob must be specified.")
flag.Usage()
os.Exit(1)
}

if *outText == "" && *outGob == "" {
fmt.Println("Specify output file paths with -outText and/or -outGob.")
fmt.Fprintln(os.Stderr, "Specify output file paths with -outText and/or -outGob.")
flag.Usage()
os.Exit(1)
}

data, err := mmap.ReadFile[string](inPath)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to read input file:", err)
os.Exit(1)
}
defer mmap.Unmap(data)

dsb, err := inFunc(data)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to parse input file:", err)
return
}

if *outText != "" {
fout, err := os.Create(*outText)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to create output file:", err)
return
}
defer fout.Close()

err = dsb.WriteText(fout)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to write output file:", err)
return
}
}

if *outGob != "" {
fout, err := os.Create(*outGob)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to create output file:", err)
return
}
defer fout.Close()

err = dsb.WriteGob(fout)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to write output file:", err)
return
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/shadowsocks-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
flag.Parse()

if confPath == "" {
fmt.Println("Missing -confPath <path>.")
fmt.Fprintln(os.Stderr, "Missing -confPath <path>.")
flag.Usage()
os.Exit(1)
}
Expand All @@ -54,7 +54,7 @@ func main() {
zc = zap.NewDevelopmentConfig()
default:
if err := jsonhelper.LoadAndDecodeDisallowUnknownFields(zapConf, &zc); err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to load zap logger config:", err)
os.Exit(1)
}
}
Expand All @@ -65,7 +65,7 @@ func main() {

logger, err := zc.Build()
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, "Failed to build logger:", err)
os.Exit(1)
}
defer logger.Sync()
Expand Down

0 comments on commit 4fbdbab

Please sign in to comment.