fix: panic when proto file not exist

This commit is contained in:
xuthus5 2024-03-20 23:46:57 +08:00
parent c57b75721e
commit 323617361d
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
2 changed files with 9 additions and 11 deletions

View File

@ -1,7 +1,6 @@
package bootstrap package bootstrap
import ( import (
"errors"
"os" "os"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -56,17 +55,16 @@ func AddServiceCommand() *cobra.Command {
return return
} }
err := gobuf.CreateFile(pbPath)
if err != nil {
logrus.Errorf("read proto file failed (when create new file): %v", err)
return
}
buf, err := gobuf.NewParser(pbPath) buf, err := gobuf.NewParser(pbPath)
if err != nil { if err != nil {
if !errors.Is(err, os.ErrNotExist) { logrus.Errorf("read proto file failed: %v", err)
logrus.Errorf("read proto file failed: %v", err) return
return
}
err := buf.CreateFile(pbPath)
if err != nil {
logrus.Errorf("read proto file failed (when create new file): %v", err)
return
}
} }
if buf.ExistService(svcName) { if buf.ExistService(svcName) {

2
go.mod
View File

@ -6,7 +6,7 @@ require (
code.gitea.io/sdk/gitea v0.17.1 code.gitea.io/sdk/gitea v0.17.1
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0 github.com/spf13/cobra v1.8.0
gitter.top/common/gobuf v0.0.3 gitter.top/common/gobuf v0.0.4
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )