summaryrefslogtreecommitdiffstats
path: root/commands/limit_darwin.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-12-02 11:42:53 +0100
committerAnthony Fok <foka@debian.org>2015-12-02 07:07:05 -0700
commit3f0f7eed68f44486c1e053bbce25c46c1d52a12f (patch)
tree4bafd37bcd2ede6fb1c7f5838679a345dae83668 /commands/limit_darwin.go
parent6959b7fa80f22aead6fa8c9b8ff3c4b8cc222a30 (diff)
Improve error handling in commands
Cobra, the CLI commander in use in Hugo, has some long awaited improvements in the error handling department. This enables a more centralized error handling approach. This commit introduces that by changing all the command funcs to `RunE`: * The core part of the error logging, usage logging and `os.Exit(-1)` is now performed in one place and that one place only. * The usage text is now only shown on invalid arguments etc. (user errors) Fixes #1502
Diffstat (limited to 'commands/limit_darwin.go')
-rw-r--r--commands/limit_darwin.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/commands/limit_darwin.go b/commands/limit_darwin.go
index 274505073..ab8dba0f7 100644
--- a/commands/limit_darwin.go
+++ b/commands/limit_darwin.go
@@ -30,12 +30,13 @@ var limit = &cobra.Command{
Short: "Check system ulimit settings",
Long: `Hugo will inspect the current ulimit settings on the system.
This is primarily to ensure that Hugo can watch enough files on some OSs`,
- Run: func(cmd *cobra.Command, args []string) {
+ RunE: func(cmd *cobra.Command, args []string) error {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
- jww.ERROR.Println("Error Getting Rlimit ", err)
+ return newSystemError("Error Getting Rlimit ", err)
}
+
jww.FEEDBACK.Println("Current rLimit:", rLimit)
jww.FEEDBACK.Println("Attempting to increase limit")
@@ -43,13 +44,15 @@ var limit = &cobra.Command{
rLimit.Cur = 999999
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
- jww.ERROR.Println("Error Setting rLimit ", err)
+ return newSystemError("Error Setting rLimit ", err)
}
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
- jww.ERROR.Println("Error Getting rLimit ", err)
+ return newSystemError("Error Getting rLimit ", err)
}
jww.FEEDBACK.Println("rLimit after change:", rLimit)
+
+ return nil
},
}