♻️ 将退出码移到 logging 项目中
This commit is contained in:
parent
e99b7fd588
commit
2601605953
13 changed files with 29 additions and 39 deletions
|
@ -108,7 +108,7 @@ func removeWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
|
||||
if util.WorkspaceDir == path && (util.ContainerIOS == util.Container || util.ContainerAndroid == util.Container) {
|
||||
os.Exit(util.ExitCodeOk)
|
||||
os.Exit(logging.ExitCodeOk)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
|
|||
if nil != err {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", p, err)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(util.ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
@ -97,7 +97,7 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
|
|||
} else {
|
||||
logging.LogWarnf("read parent tree data [%s] failed: %s", parentAbsPath, readErr)
|
||||
if errors.Is(readErr, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(util.ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ require (
|
|||
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b
|
||||
github.com/siyuan-note/filelock v0.0.0-20230223100551-200cbe1cf84e
|
||||
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc
|
||||
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb
|
||||
github.com/siyuan-note/logging v0.0.0-20230318100514-8ece27db458d
|
||||
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7
|
||||
github.com/steambap/captcha v1.4.1
|
||||
github.com/studio-b12/gowebdav v0.0.0-20230203202212-3282f94193f2
|
||||
|
|
|
@ -289,6 +289,8 @@ github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc h1:MX2cPWpn
|
|||
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc/go.mod h1:WDO42mUVRnkk8M4AhZ4oakZ5jnghulP0c8NFCrrFWG4=
|
||||
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb h1:qzz7ZQw7/tHJd1IST+8UymXFF8RacokMLD7VZgyS+ww=
|
||||
github.com/siyuan-note/logging v0.0.0-20230223101545-ec2cbf198ffb/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
|
||||
github.com/siyuan-note/logging v0.0.0-20230318100514-8ece27db458d h1:K7y9mEvoQ2PZkM0f+bHvnyDi/gnKfY5OJjYUe2GFnpc=
|
||||
github.com/siyuan-note/logging v0.0.0-20230318100514-8ece27db458d/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
|
||||
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7 h1:Kr8hhMhr6v+U24TMDCP5WdP4dWrXm5maar+TycTZs9I=
|
||||
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7/go.mod h1:XJtLlKCr8cZE+lzykM4edHHih92M9M50UNw/nDLYRN8=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
|
|
|
@ -491,7 +491,7 @@ func fullReindex() {
|
|||
WaitForWritingFiles()
|
||||
|
||||
if err := sql.InitDatabase(true); nil != err {
|
||||
os.Exit(util.ExitCodeReadOnlyDatabase)
|
||||
os.Exit(logging.ExitCodeReadOnlyDatabase)
|
||||
return
|
||||
}
|
||||
treenode.InitBlockTree(true)
|
||||
|
|
|
@ -463,7 +463,7 @@ func Close(force bool, execInstallPkg int) (exitCode int) {
|
|||
}
|
||||
logging.LogInfof("exited kernel")
|
||||
util.WebSocketServer.Close()
|
||||
os.Exit(util.ExitCodeOk)
|
||||
os.Exit(logging.ExitCodeOk)
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@ func setCriteria(criteria []*Criterion) (err error) {
|
|||
if nil != err {
|
||||
logging.LogErrorf("write storage [criteria] failed: %s", err)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(util.ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
@ -279,7 +279,7 @@ func getCriteria() (ret []*Criterion, err error) {
|
|||
if nil != err {
|
||||
logging.LogErrorf("read storage [criteria] failed: %s", err)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(util.ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
@ -354,7 +354,7 @@ func setLocalStorage(val interface{}) (err error) {
|
|||
if nil != err {
|
||||
logging.LogErrorf("write storage [local] failed: %s", err)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(util.ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
@ -373,7 +373,7 @@ func getLocalStorage() (ret map[string]interface{}, err error) {
|
|||
if nil != err {
|
||||
logging.LogErrorf("read storage [local] failed: %s", err)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(util.ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
@ -84,7 +84,7 @@ func Serve(fastMode bool) {
|
|||
if nil != err {
|
||||
if !fastMode {
|
||||
logging.LogErrorf("boot kernel failed: %s", err)
|
||||
os.Exit(util.ExitCodeUnavailablePort)
|
||||
os.Exit(logging.ExitCodeUnavailablePort)
|
||||
}
|
||||
|
||||
// fast 模式下启动失败则直接返回
|
||||
|
@ -95,7 +95,7 @@ func Serve(fastMode bool) {
|
|||
if nil != err {
|
||||
if !fastMode {
|
||||
logging.LogErrorf("boot kernel failed: %s", err)
|
||||
os.Exit(util.ExitCodeUnavailablePort)
|
||||
os.Exit(logging.ExitCodeUnavailablePort)
|
||||
}
|
||||
}
|
||||
util.ServerPort = port
|
||||
|
@ -129,7 +129,7 @@ func Serve(fastMode bool) {
|
|||
if err = http.Serve(ln, ginServer); nil != err {
|
||||
if !fastMode {
|
||||
logging.LogErrorf("boot kernel failed: %s", err)
|
||||
os.Exit(util.ExitCodeUnavailablePort)
|
||||
os.Exit(logging.ExitCodeUnavailablePort)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1148,7 +1148,7 @@ func beginTx() (tx *sql.Tx, err error) {
|
|||
if tx, err = db.Begin(); nil != err {
|
||||
logging.LogErrorf("begin tx failed: %s\n %s", err, logging.ShortStack())
|
||||
if strings.Contains(err.Error(), "database is locked") {
|
||||
os.Exit(util.ExitCodeReadOnlyDatabase)
|
||||
os.Exit(logging.ExitCodeReadOnlyDatabase)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -1158,7 +1158,7 @@ func beginHistoryTx() (tx *sql.Tx, err error) {
|
|||
if tx, err = historyDB.Begin(); nil != err {
|
||||
logging.LogErrorf("begin history tx failed: %s\n %s", err, logging.ShortStack())
|
||||
if strings.Contains(err.Error(), "database is locked") {
|
||||
os.Exit(util.ExitCodeReadOnlyDatabase)
|
||||
os.Exit(logging.ExitCodeReadOnlyDatabase)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -325,7 +325,7 @@ func InitBlockTree(force bool) {
|
|||
entries, err := os.ReadDir(util.BlockTreePath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read block tree dir failed: %s", err)
|
||||
os.Exit(util.ExitCodeBlockTreeErr)
|
||||
os.Exit(logging.ExitCodeBlockTreeErr)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ func InitBlockTree(force bool) {
|
|||
fh, err = os.OpenFile(p, os.O_RDWR, 0644)
|
||||
if nil != err {
|
||||
logging.LogErrorf("open block tree file failed: %s", err)
|
||||
os.Exit(util.ExitCodeBlockTreeErr)
|
||||
os.Exit(logging.ExitCodeBlockTreeErr)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,7 @@ func InitBlockTree(force bool) {
|
|||
fh.Close()
|
||||
if nil != err {
|
||||
logging.LogErrorf("read block tree failed: %s", err)
|
||||
os.Exit(util.ExitCodeBlockTreeErr)
|
||||
os.Exit(logging.ExitCodeBlockTreeErr)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ func InitBlockTree(force bool) {
|
|||
if err = os.RemoveAll(util.BlockTreePath); nil != err {
|
||||
logging.LogErrorf("removed corrupted block tree failed: %s", err)
|
||||
}
|
||||
os.Exit(util.ExitCodeBlockTreeErr)
|
||||
os.Exit(logging.ExitCodeBlockTreeErr)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ func SaveBlockTree(force bool) {
|
|||
data, err := msgpack.Marshal(slice.data)
|
||||
if nil != err {
|
||||
logging.LogErrorf("marshal block tree failed: %s", err)
|
||||
os.Exit(util.ExitCodeBlockTreeErr)
|
||||
os.Exit(logging.ExitCodeBlockTreeErr)
|
||||
return false
|
||||
}
|
||||
slice.m.Unlock()
|
||||
|
@ -418,7 +418,7 @@ func SaveBlockTree(force bool) {
|
|||
p := filepath.Join(util.BlockTreePath, key.(string)) + ".msgpack"
|
||||
if err = gulu.File.WriteFileSafer(p, data, 0644); nil != err {
|
||||
logging.LogErrorf("write block tree failed: %s", err)
|
||||
os.Exit(util.ExitCodeBlockTreeErr)
|
||||
os.Exit(logging.ExitCodeBlockTreeErr)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -37,18 +37,6 @@ import (
|
|||
|
||||
const DatabaseVer = "20220501" // 修改表结构的话需要修改这里
|
||||
|
||||
const (
|
||||
ExitCodeReadOnlyDatabase = 20 // 数据库文件被锁
|
||||
ExitCodeUnavailablePort = 21 // 端口不可用
|
||||
ExitCodeCreateConfDirErr = 22 // 创建配置目录失败
|
||||
ExitCodeBlockTreeErr = 23 // 无法读写 blocktree.msgpack 文件
|
||||
ExitCodeWorkspaceLocked = 24 // 工作空间已被锁定
|
||||
ExitCodeCreateWorkspaceDirErr = 25 // 创建工作空间失败
|
||||
ExitCodeFileSysInconsistent = 26 // 文件系统不一致
|
||||
ExitCodeOk = 0 // 正常退出
|
||||
ExitCodeFatal = 1 // 致命错误
|
||||
)
|
||||
|
||||
// IsExiting 是否正在退出程序。
|
||||
var IsExiting = false
|
||||
|
||||
|
@ -139,7 +127,7 @@ func ReportFileSysFatalError(err error) {
|
|||
output = strings.Join(lines[5:], "\n")
|
||||
}
|
||||
logging.LogErrorf("check file system status failed: %s, %s", err, output)
|
||||
os.Exit(ExitCodeFileSysInconsistent)
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
}
|
||||
|
||||
func CheckFileSysStatus() {
|
||||
|
|
|
@ -190,7 +190,7 @@ func initWorkspaceDir(workspaceArg string) {
|
|||
if !gulu.File.IsExist(workspaceConf) {
|
||||
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
||||
os.Exit(ExitCodeCreateConfDirErr)
|
||||
os.Exit(logging.ExitCodeCreateConfDirErr)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ func initWorkspaceDir(workspaceArg string) {
|
|||
}
|
||||
if err := os.MkdirAll(defaultWorkspaceDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
|
||||
os.Exit(ExitCodeCreateWorkspaceDirErr)
|
||||
os.Exit(logging.ExitCodeCreateWorkspaceDirErr)
|
||||
}
|
||||
|
||||
var workspacePaths []string
|
||||
|
@ -481,7 +481,7 @@ func tryLockWorkspace() {
|
|||
} else {
|
||||
logging.LogErrorf("lock workspace [%s] failed", WorkspaceDir)
|
||||
}
|
||||
os.Exit(ExitCodeWorkspaceLocked)
|
||||
os.Exit(logging.ExitCodeWorkspaceLocked)
|
||||
}
|
||||
|
||||
func IsWorkspaceLocked(workspacePath string) bool {
|
||||
|
|
|
@ -46,7 +46,7 @@ func BootMobile(container, appDir, workspaceBaseDir, lang string) {
|
|||
if !gulu.File.IsExist(userHomeConfDir) {
|
||||
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
||||
os.Exit(ExitCodeCreateConfDirErr)
|
||||
os.Exit(logging.ExitCodeCreateConfDirErr)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func BootMobile(container, appDir, workspaceBaseDir, lang string) {
|
|||
defaultWorkspaceDir := filepath.Join(workspaceBaseDir, "siyuan")
|
||||
if err := os.MkdirAll(defaultWorkspaceDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
|
||||
os.Exit(ExitCodeCreateWorkspaceDirErr)
|
||||
os.Exit(logging.ExitCodeCreateWorkspaceDirErr)
|
||||
}
|
||||
|
||||
initWorkspaceDirMobile(workspaceBaseDir)
|
||||
|
|
Loading…
Add table
Reference in a new issue