chore: tweak error message

pull/3186/head
Steven 1 year ago
parent 8101a5e0b1
commit ff81ea602d

@ -14,7 +14,7 @@ import (
"github.com/usememos/memos/internal/jobs" "github.com/usememos/memos/internal/jobs"
"github.com/usememos/memos/server" "github.com/usememos/memos/server"
_profile "github.com/usememos/memos/server/profile" "github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store" "github.com/usememos/memos/store"
"github.com/usememos/memos/store/db" "github.com/usememos/memos/store/db"
) )
@ -31,22 +31,22 @@ const (
) )
var ( var (
profile *_profile.Profile mode string
mode string addr string
addr string port int
port int data string
data string driver string
driver string dsn string
dsn string serveFrontend bool
serveFrontend bool allowedOrigins []string
allowedOrigins []string instanceProfile *profile.Profile
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
Use: "memos", Use: "memos",
Short: `An open source, lightweight note-taking service. Easily capture and share your great thoughts.`, Short: `An open source, lightweight note-taking service. Easily capture and share your great thoughts.`,
Run: func(_cmd *cobra.Command, _args []string) { Run: func(_cmd *cobra.Command, _args []string) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
dbDriver, err := db.NewDBDriver(profile) dbDriver, err := db.NewDBDriver(instanceProfile)
if err != nil { if err != nil {
cancel() cancel()
slog.Error("failed to create db driver", err) slog.Error("failed to create db driver", err)
@ -58,14 +58,14 @@ var (
return return
} }
storeInstance := store.New(dbDriver, profile) storeInstance := store.New(dbDriver, instanceProfile)
if err := storeInstance.MigrateManually(ctx); err != nil { if err := storeInstance.MigrateManually(ctx); err != nil {
cancel() cancel()
slog.Error("failed to migrate manually", err) slog.Error("failed to migrate manually", err)
return return
} }
s, err := server.NewServer(ctx, profile, storeInstance) s, err := server.NewServer(ctx, instanceProfile, storeInstance)
if err != nil { if err != nil {
cancel() cancel()
slog.Error("failed to create server", err) slog.Error("failed to create server", err)
@ -162,7 +162,7 @@ func init() {
func initConfig() { func initConfig() {
viper.AutomaticEnv() viper.AutomaticEnv()
var err error var err error
profile, err = _profile.GetProfile() instanceProfile, err = profile.GetProfile()
if err != nil { if err != nil {
fmt.Printf("failed to get profile, error: %+v\n", err) fmt.Printf("failed to get profile, error: %+v\n", err)
return return
@ -179,15 +179,15 @@ mode: %s
driver: %s driver: %s
frontend: %t frontend: %t
--- ---
`, profile.Version, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Driver, profile.Frontend) `, instanceProfile.Version, instanceProfile.Data, instanceProfile.DSN, instanceProfile.Addr, instanceProfile.Port, instanceProfile.Mode, instanceProfile.Driver, instanceProfile.Frontend)
} }
func printGreetings() { func printGreetings() {
print(greetingBanner) print(greetingBanner)
if len(profile.Addr) == 0 { if len(instanceProfile.Addr) == 0 {
fmt.Printf("Version %s has been started on port %d\n", profile.Version, profile.Port) fmt.Printf("Version %s has been started on port %d\n", instanceProfile.Version, instanceProfile.Port)
} else { } else {
fmt.Printf("Version %s has been started on address '%s' and port %d\n", profile.Version, profile.Addr, profile.Port) fmt.Printf("Version %s has been started on address '%s' and port %d\n", instanceProfile.Version, instanceProfile.Addr, instanceProfile.Port)
} }
fmt.Printf(`--- fmt.Printf(`---
See more in: See more in:

@ -30,7 +30,7 @@ func (s *APIV2Service) GetAuthStatus(ctx context.Context, _ *apiv2pb.GetAuthStat
if user == nil { if user == nil {
// Set the cookie header to expire access token. // Set the cookie header to expire access token.
if err := s.clearAccessTokenCookie(ctx); err != nil { if err := s.clearAccessTokenCookie(ctx); err != nil {
return nil, status.Errorf(codes.Internal, "failed to set grpc header") return nil, status.Errorf(codes.Internal, "failed to set grpc header: %v", err)
} }
return nil, status.Errorf(codes.Unauthenticated, "user not found") return nil, status.Errorf(codes.Unauthenticated, "user not found")
} }

@ -106,7 +106,7 @@ func (s *APIV2Service) ListMemos(ctx context.Context, request *apiv2pb.ListMemos
memoFind.Offset = &offset memoFind.Offset = &offset
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list memos") return nil, status.Errorf(codes.Internal, "failed to list memos: %v", err)
} }
memoMessages := []*apiv2pb.Memo{} memoMessages := []*apiv2pb.Memo{}
@ -459,7 +459,7 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list memos") return nil, status.Errorf(codes.Internal, "failed to list memos: %v", err)
} }
location, err := time.LoadLocation(request.Timezone) location, err := time.LoadLocation(request.Timezone)
@ -494,12 +494,12 @@ func (s *APIV2Service) ExportMemos(ctx context.Context, request *apiv2pb.ExportM
ExcludeComments: true, ExcludeComments: true,
} }
if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil { if err := s.buildMemoFindWithFilter(ctx, memoFind, request.Filter); err != nil {
return nil, status.Errorf(codes.Internal, "failed to build find memos with filter") return nil, status.Errorf(codes.Internal, "failed to build find memos with filter: %v", err)
} }
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list memos") return nil, status.Errorf(codes.Internal, "failed to list memos: %v", err)
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)

Loading…
Cancel
Save