mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
♻️ Refactor Go to err != nil, err == nil (#12385)
This commit is contained in:
parent
473a159ef2
commit
b100721fee
147 changed files with 1661 additions and 1659 deletions
|
|
@ -42,13 +42,13 @@ func ConvertPandoc(dir string, args ...string) (path string, err error) {
|
|||
gulu.CmdAttr(pandoc)
|
||||
path = filepath.Join("temp", "convert", "pandoc", dir)
|
||||
absPath := filepath.Join(WorkspaceDir, path)
|
||||
if err = os.MkdirAll(absPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(absPath, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", absPath, err)
|
||||
return
|
||||
}
|
||||
pandoc.Dir = absPath
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.Join(err, errors.New(string(output)))
|
||||
logging.LogErrorf("pandoc convert output failed: %s", err)
|
||||
return
|
||||
|
|
@ -59,7 +59,7 @@ func ConvertPandoc(dir string, args ...string) (path string, err error) {
|
|||
|
||||
func Pandoc(from, to, o, content string) (err error) {
|
||||
if "" == from || "" == to || "md" == to {
|
||||
if err = gulu.File.WriteFileSafer(o, []byte(content), 0644); nil != err {
|
||||
if err = gulu.File.WriteFileSafer(o, []byte(content), 0644); err != nil {
|
||||
logging.LogErrorf("write export markdown file [%s] failed: %s", o, err)
|
||||
}
|
||||
return
|
||||
|
|
@ -71,12 +71,12 @@ func Pandoc(from, to, o, content string) (err error) {
|
|||
}
|
||||
|
||||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc", gulu.Rand.String(7))
|
||||
if err = os.MkdirAll(dir, 0755); nil != err {
|
||||
if err = os.MkdirAll(dir, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err)
|
||||
return
|
||||
}
|
||||
tmpPath := filepath.Join(dir, gulu.Rand.String(7))
|
||||
if err = os.WriteFile(tmpPath, []byte(content), 0644); nil != err {
|
||||
if err = os.WriteFile(tmpPath, []byte(content), 0644); err != nil {
|
||||
logging.LogErrorf("write file failed: [%s]", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ func Pandoc(from, to, o, content string) (err error) {
|
|||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
gulu.CmdAttr(pandoc)
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("pandoc convert output [%s], error [%s]", string(output), err)
|
||||
return
|
||||
}
|
||||
|
|
@ -113,9 +113,9 @@ func InitPandoc() {
|
|||
|
||||
if confPath := filepath.Join(ConfDir, "conf.json"); gulu.File.IsExist(confPath) {
|
||||
// Workspace built-in Pandoc is no longer initialized after customizing Pandoc path https://github.com/siyuan-note/siyuan/issues/8377
|
||||
if data, err := os.ReadFile(confPath); nil == err {
|
||||
if data, err := os.ReadFile(confPath); err == nil {
|
||||
conf := map[string]interface{}{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &conf); nil == err && nil != conf["export"] {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &conf); err == nil && nil != conf["export"] {
|
||||
export := conf["export"].(map[string]interface{})
|
||||
if customPandocBinPath := export["pandocBin"].(string); !strings.HasPrefix(customPandocBinPath, pandocDir) {
|
||||
if pandocVer := getPandocVer(customPandocBinPath); "" != pandocVer {
|
||||
|
|
@ -164,7 +164,7 @@ func InitPandoc() {
|
|||
return
|
||||
}
|
||||
|
||||
if err := gulu.Zip.Unzip(pandocZip, pandocDir); nil != err {
|
||||
if err := gulu.Zip.Unzip(pandocZip, pandocDir); err != nil {
|
||||
logging.LogErrorf("unzip pandoc failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ func getPandocVer(binPath string) (ret string) {
|
|||
cmd := exec.Command(binPath, "--version")
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err := cmd.CombinedOutput()
|
||||
if nil == err && strings.HasPrefix(string(data), "pandoc") {
|
||||
if err == nil && strings.HasPrefix(string(data), "pandoc") {
|
||||
parts := bytes.Split(data, []byte("\n"))
|
||||
if 0 < len(parts) {
|
||||
ret = strings.TrimPrefix(string(parts[0]), "pandoc")
|
||||
|
|
@ -204,7 +204,7 @@ func IsValidPandocBin(binPath string) bool {
|
|||
cmd := exec.Command(binPath, "--version")
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err := cmd.CombinedOutput()
|
||||
if nil == err && strings.HasPrefix(string(data), "pandoc") {
|
||||
if err == nil && strings.HasPrefix(string(data), "pandoc") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue