c9b72206a5
* Checkpoint: it builds The config, db, model, network, os, and public packages have had some fixes to glaringly obvious flaws, dead code removed, and stylistic changes. * Style changes and old code removal in router Router needs a lot of work done to its (lack of) error handling. * Dead code removal and style changes Now up to util/email/email.go. After I'm finished with the initial sweep I'll go back and fix error handling and security issues. Then I'll fix the broken API. Then I'll go through to add documentation and fix code visibility. * Finish dead code removal and style changes Vendored libraries not touched. Everything still needs security fixes and documentation. There's also one case of broken functionality. * Fix accidental find-and-replace * Style, error checking, saftey, bug fix changes * Redo error checking erased during merge * Re-add merge-erased fix. Make Safe safe.
27 lignes
766 o
Go
27 lignes
766 o
Go
package log
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/Sirupsen/logrus"
|
|
"runtime"
|
|
)
|
|
|
|
// CheckError check error and return true if error is nil and return false if error is not nil.
|
|
func CheckError(err error) bool {
|
|
return CheckErrorWithMessage(err, "")
|
|
}
|
|
|
|
// CheckErrorWithMessage check error with message and log messages with stack. And then return true if error is nil and return false if error is not nil.
|
|
func CheckErrorWithMessage(err error, msg string, args ...interface{}) bool {
|
|
if err != nil {
|
|
var stack [4096]byte
|
|
runtime.Stack(stack[:], false)
|
|
if len(args) == 0 {
|
|
logrus.Error(msg + fmt.Sprintf("%q\n%s\n", err, stack[:]))
|
|
} else {
|
|
logrus.Error(fmt.Sprintf(msg, args...) + fmt.Sprintf("%q\n%s\n", err, stack[:]))
|
|
}
|
|
return false
|
|
}
|
|
return true
|
|
}
|