From cb9b0056d7c5243ca22e5394256f922d5084442d Mon Sep 17 00:00:00 2001 From: rot1024 Date: Wed, 28 Jun 2023 19:29:41 +0900 Subject: [PATCH] use context on logging --- server/go.mod | 6 +- server/go.sum | 9 +- server/internal/app/app.go | 2 +- server/internal/app/repo.go | 4 +- .../infrastructure/adapter/property_schema.go | 8 +- .../infrastructure/auth0/authenticator.go | 10 +- .../auth0/authenticator_test.go | 3 +- server/internal/infrastructure/fs/file.go | 20 +-- server/internal/infrastructure/fs/plugin.go | 18 +-- .../infrastructure/fs/property_schema.go | 10 +- server/internal/infrastructure/gcs/file.go | 56 ++++---- .../infrastructure/marketplace/marketplace.go | 24 ++-- server/internal/infrastructure/mongo/asset.go | 8 +- .../internal/infrastructure/mongo/config.go | 6 +- .../internal/infrastructure/mongo/dataset.go | 14 +- .../infrastructure/mongo/dataset_schema.go | 4 +- server/internal/infrastructure/mongo/layer.go | 2 +- server/internal/infrastructure/mongo/lock.go | 10 +- .../201217132559_add_scene_widget_id.go | 4 +- .../201217193948_add_scene_default_tile.go | 4 +- .../210310145844_remove_preview_token.go | 4 +- .../210730175108_add_scene_align_system.go | 4 +- ...220214180713_split_schema_of_properties.go | 4 +- ...4648_add_scene_field_to_property_schema.go | 4 +- .../221028204300_move_terrain_properties.go | 4 +- .../internal/infrastructure/mongo/project.go | 10 +- .../internal/infrastructure/mongo/property.go | 2 +- .../infrastructure/mongo/scene_lock.go | 4 +- server/internal/infrastructure/mongo/tag.go | 2 +- server/internal/infrastructure/s3/s3.go | 31 +++-- .../internal/usecase/gateway/authenticator.go | 4 +- server/internal/usecase/interactor/dataset.go | 4 +- .../usecase/interactor/plugin_common.go | 6 +- .../usecase/interactor/plugin_upload.go | 6 +- .../internal/usecase/interactor/published.go | 6 +- server/internal/usecase/interactor/user.go | 2 +- server/pkg/log/gceformatter.go | 123 ------------------ server/pkg/log/log.go | 108 --------------- server/pkg/plugin/pluginpack/package.go | 3 +- server/pkg/scene/sceneops/plugin_installer.go | 20 +-- server/pkg/scene/sceneops/plugin_migrator.go | 2 +- 41 files changed, 173 insertions(+), 402 deletions(-) delete mode 100644 server/pkg/log/gceformatter.go delete mode 100644 server/pkg/log/log.go diff --git a/server/go.mod b/server/go.mod index 2d740a5be0..c4708f025b 100644 --- a/server/go.mod +++ b/server/go.mod @@ -21,14 +21,12 @@ require ( github.com/kelseyhightower/envconfig v1.4.0 github.com/kennygrant/sanitize v1.2.4 github.com/labstack/echo/v4 v4.7.2 - github.com/labstack/gommon v0.3.1 github.com/mitchellh/mapstructure v1.5.0 github.com/paulmach/go.geojson v1.4.0 github.com/pkg/errors v0.9.1 github.com/ravilushqa/otelgqlgen v0.8.0 - github.com/reearth/reearthx v0.0.0-20230628094334-9f836a79dabb + github.com/reearth/reearthx v0.0.0-20230628100740-772ae55edde1 github.com/samber/lo v1.27.0 - github.com/sirupsen/logrus v1.8.1 github.com/spf13/afero v1.9.3 github.com/square/mongo-lock v0.0.0-20201208161834-4db518ed7fb2 github.com/stretchr/testify v1.8.0 @@ -112,6 +110,7 @@ require ( github.com/imkira/go-interpol v1.0.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/klauspost/compress v1.13.6 // indirect + github.com/labstack/gommon v0.3.1 // indirect github.com/maruel/panicparse/v2 v2.3.1 // indirect github.com/matryer/moq v0.2.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -125,6 +124,7 @@ require ( github.com/sendgrid/rest v2.6.9+incompatible // indirect github.com/sendgrid/sendgrid-go v3.12.0+incompatible // indirect github.com/sergi/go-diff v1.1.0 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect github.com/smartystreets/assertions v1.1.1 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect github.com/urfave/cli/v2 v2.8.1 // indirect diff --git a/server/go.sum b/server/go.sum index 51a1e6f406..6ba3f65c01 100644 --- a/server/go.sum +++ b/server/go.sum @@ -80,6 +80,7 @@ github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy86 github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= @@ -492,12 +493,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/ravilushqa/otelgqlgen v0.8.0 h1:x48k+D1GMgm87xhMO2Lekrr9YGzFbpG3yijn9GpxuAY= github.com/ravilushqa/otelgqlgen v0.8.0/go.mod h1:6JO5YO2iY4POC7R6yB/L/RKXCcyISL8qQt5NnHOhh0o= -github.com/reearth/reearthx v0.0.0-20230530055440-86a8d4675853 h1:eO1u6WJ/B1j/uC0ZnHS21EYuaREbdYDgHAExy7LLAnw= -github.com/reearth/reearthx v0.0.0-20230530055440-86a8d4675853/go.mod h1:Rh7MJPKq43f+HZ/PwjZ5vEbGPpllNFvUrxn9sBn2b+s= -github.com/reearth/reearthx v0.0.0-20230628083626-a5efdcea5ff3 h1:TWAum5PQ1lNOg+TfBFL9lpw9Z0V7d0TCqxNQTQHOUoQ= -github.com/reearth/reearthx v0.0.0-20230628083626-a5efdcea5ff3/go.mod h1:Rh7MJPKq43f+HZ/PwjZ5vEbGPpllNFvUrxn9sBn2b+s= -github.com/reearth/reearthx v0.0.0-20230628094334-9f836a79dabb h1:tCYnqv0N2kwx90fMjUHEnsYfbiChJGeXdl+NMHPJCxY= -github.com/reearth/reearthx v0.0.0-20230628094334-9f836a79dabb/go.mod h1:O4zFr6ks8jDKfgy9NBpZKp31jpmAPnfOtMQK9B6xX54= +github.com/reearth/reearthx v0.0.0-20230628100740-772ae55edde1 h1:jt73WlNFZQ8m7tvhyOyVcLLmtlEr+a8g3ZzGU1aLqwg= +github.com/reearth/reearthx v0.0.0-20230628100740-772ae55edde1/go.mod h1:O4zFr6ks8jDKfgy9NBpZKp31jpmAPnfOtMQK9B6xX54= github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/server/internal/app/app.go b/server/internal/app/app.go index d0e79e29ee..ea662ee8ee 100644 --- a/server/internal/app/app.go +++ b/server/internal/app/app.go @@ -76,7 +76,7 @@ func initEcho(ctx context.Context, cfg *ServerConfig) *echo.Echo { e.GET("/graphql", echo.WrapHandler( playground.Handler("reearth", "/api/graphql"), )) - log.Infof("gql: GraphQL Playground is available") + log.Infofc(ctx, "gql: GraphQL Playground is available") } // init usecases diff --git a/server/internal/app/repo.go b/server/internal/app/repo.go index 1ead95a600..704823e818 100644 --- a/server/internal/app/repo.go +++ b/server/internal/app/repo.go @@ -70,7 +70,7 @@ func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool) func initFile(ctx context.Context, conf *config.Config) (fileRepo gateway.File) { var err error if conf.GCS.IsConfigured() { - log.Infof("file: GCS storage is used: %s\n", conf.GCS.BucketName) + log.Infofc(ctx, "file: GCS storage is used: %s\n", conf.GCS.BucketName) fileRepo, err = gcs.NewFile(conf.GCS.BucketName, conf.AssetBaseURL, conf.GCS.PublicationCacheControl) if err != nil { log.Warnf("file: failed to init GCS storage: %s\n", err.Error()) @@ -80,7 +80,7 @@ func initFile(ctx context.Context, conf *config.Config) (fileRepo gateway.File) } if conf.S3.IsConfigured() { - log.Infof("file: S3 storage is used: %s\n", conf.S3.BucketName) + log.Infofc(ctx, "file: S3 storage is used: %s\n", conf.S3.BucketName) fileRepo, err = s3.NewS3(ctx, conf.S3.BucketName, conf.AssetBaseURL, conf.S3.PublicationCacheControl) if err != nil { log.Warnf("file: failed to init S3 storage: %s\n", err.Error()) diff --git a/server/internal/infrastructure/adapter/property_schema.go b/server/internal/infrastructure/adapter/property_schema.go index 43e6bef51a..bfb6b6081c 100644 --- a/server/internal/infrastructure/adapter/property_schema.go +++ b/server/internal/infrastructure/adapter/property_schema.go @@ -64,28 +64,28 @@ func (r *propertySchema) FindByIDs(ctx context.Context, ids []id.PropertySchemaI func (r *propertySchema) Save(ctx context.Context, p *property.Schema) error { if r.writer == nil { - return rerror.ErrInternalBy(errors.New("writer is not set")) + return rerror.ErrInternalByWithContext(ctx, errors.New("writer is not set")) } return r.writer.Save(ctx, p) } func (r *propertySchema) SaveAll(ctx context.Context, p property.SchemaList) error { if r.writer == nil { - return rerror.ErrInternalBy(errors.New("writer is not set")) + return rerror.ErrInternalByWithContext(ctx, errors.New("writer is not set")) } return r.writer.SaveAll(ctx, p) } func (r *propertySchema) Remove(ctx context.Context, p id.PropertySchemaID) error { if r.writer == nil { - return rerror.ErrInternalBy(errors.New("writer is not set")) + return rerror.ErrInternalByWithContext(ctx, errors.New("writer is not set")) } return r.writer.Remove(ctx, p) } func (r *propertySchema) RemoveAll(ctx context.Context, p []id.PropertySchemaID) error { if r.writer == nil { - return rerror.ErrInternalBy(errors.New("writer is not set")) + return rerror.ErrInternalByWithContext(ctx, errors.New("writer is not set")) } return r.writer.RemoveAll(ctx, p) } diff --git a/server/internal/infrastructure/auth0/authenticator.go b/server/internal/infrastructure/auth0/authenticator.go index 5d7527e724..30b629436b 100644 --- a/server/internal/infrastructure/auth0/authenticator.go +++ b/server/internal/infrastructure/auth0/authenticator.go @@ -72,7 +72,7 @@ func New(domain, clientID, clientSecret string) *Auth0 { } } -func (a *Auth0) UpdateUser(p gateway.AuthenticatorUpdateUserParam) (data gateway.AuthenticatorUser, err error) { +func (a *Auth0) UpdateUser(ctx context.Context, p gateway.AuthenticatorUpdateUserParam) (data gateway.AuthenticatorUser, err error) { if err != nil { return } @@ -93,7 +93,7 @@ func (a *Auth0) UpdateUser(p gateway.AuthenticatorUpdateUserParam) (data gateway } var r response - r, err = a.exec(http.MethodPatch, "api/v2/users/"+p.ID, payload) + r, err = a.exec(ctx, http.MethodPatch, "api/v2/users/"+p.ID, payload) if err != nil { err = rerror.ErrInternalByWith("failed to update user", err) return @@ -103,7 +103,7 @@ func (a *Auth0) UpdateUser(p gateway.AuthenticatorUpdateUserParam) (data gateway return } -func (a *Auth0) exec(method, path string, b any) (r response, err error) { +func (a *Auth0) exec(ctx context.Context, method, path string, b any) (r response, err error) { if a == nil || a.base == "" { err = errors.New("auth0: domain is not set") return @@ -124,7 +124,7 @@ func (a *Auth0) exec(method, path string, b any) (r response, err error) { } var req *http.Request - req, err = http.NewRequest(method, a.base+path, body) + req, err = http.NewRequestWithContext(ctx, method, a.base+path, body) if err != nil { return } @@ -144,7 +144,7 @@ func (a *Auth0) exec(method, path string, b any) (r response, err error) { } if !a.disableLogging { - log.Infof("auth0: path: %s, status: %d, resp: %s", path, resp.StatusCode, respb) + log.Infofc(ctx, "auth0: path: %s, status: %d, resp: %s", path, resp.StatusCode, respb) } if err = json.Unmarshal(respb, &r); err != nil { diff --git a/server/internal/infrastructure/auth0/authenticator_test.go b/server/internal/infrastructure/auth0/authenticator_test.go index 84c2a4b4f1..67c9059fe1 100644 --- a/server/internal/infrastructure/auth0/authenticator_test.go +++ b/server/internal/infrastructure/auth0/authenticator_test.go @@ -1,6 +1,7 @@ package auth0 import ( + "context" "encoding/json" "net/http" "strings" @@ -88,7 +89,7 @@ func TestAuth0(t *testing.T) { }) newEmail := "xxxxx" - r, err := a.UpdateUser(gateway.AuthenticatorUpdateUserParam{ + r, err := a.UpdateUser(context.Background(), gateway.AuthenticatorUpdateUserParam{ ID: userID, Email: &newEmail, }) diff --git a/server/internal/infrastructure/fs/file.go b/server/internal/infrastructure/fs/file.go index 8171b4d886..2a8226da4d 100644 --- a/server/internal/infrastructure/fs/file.go +++ b/server/internal/infrastructure/fs/file.go @@ -102,7 +102,7 @@ func (f *fileRepo) RemoveBuiltScene(ctx context.Context, name string) error { // helpers -func (f *fileRepo) read(_ context.Context, filename string) (io.ReadCloser, error) { +func (f *fileRepo) read(ctx context.Context, filename string) (io.ReadCloser, error) { if filename == "" { return nil, rerror.ErrNotFound } @@ -112,25 +112,25 @@ func (f *fileRepo) read(_ context.Context, filename string) (io.ReadCloser, erro if os.IsNotExist(err) { return nil, rerror.ErrNotFound } - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } return file, nil } -func (f *fileRepo) upload(_ context.Context, filename string, content io.Reader) (int64, error) { +func (f *fileRepo) upload(ctx context.Context, filename string, content io.Reader) (int64, error) { if filename == "" { return 0, gateway.ErrFailedToUploadFile } if fnd := filepath.Dir(filename); fnd != "" { if err := f.fs.MkdirAll(fnd, 0755); err != nil { - return 0, rerror.ErrInternalBy(err) + return 0, rerror.ErrInternalByWithContext(ctx, err) } } dest, err := f.fs.Create(filename) if err != nil { - return 0, rerror.ErrInternalBy(err) + return 0, rerror.ErrInternalByWithContext(ctx, err) } defer func() { _ = dest.Close() @@ -144,14 +144,14 @@ func (f *fileRepo) upload(_ context.Context, filename string, content io.Reader) return size, nil } -func (f *fileRepo) move(_ context.Context, from, dest string) error { +func (f *fileRepo) move(ctx context.Context, from, dest string) error { if from == "" || dest == "" || from == dest { return gateway.ErrInvalidFile } if destd := filepath.Dir(dest); destd != "" { if err := f.fs.MkdirAll(destd, 0755); err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } } @@ -159,13 +159,13 @@ func (f *fileRepo) move(_ context.Context, from, dest string) error { if os.IsNotExist(err) { return rerror.ErrNotFound } - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } -func (f *fileRepo) delete(_ context.Context, filename string) error { +func (f *fileRepo) delete(ctx context.Context, filename string) error { if filename == "" { return gateway.ErrFailedToUploadFile } @@ -174,7 +174,7 @@ func (f *fileRepo) delete(_ context.Context, filename string) error { if os.IsNotExist(err) { return nil } - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } diff --git a/server/internal/infrastructure/fs/plugin.go b/server/internal/infrastructure/fs/plugin.go index a7b01eb625..cfceea75a5 100644 --- a/server/internal/infrastructure/fs/plugin.go +++ b/server/internal/infrastructure/fs/plugin.go @@ -33,7 +33,7 @@ func (r *pluginRepo) Filtered(f repo.SceneFilter) repo.Plugin { } func (r *pluginRepo) FindByID(ctx context.Context, pid id.PluginID) (*plugin.Plugin, error) { - m, err := readPluginManifest(r.fs, pid) + m, err := readPluginManifest(ctx, r.fs, pid) if err != nil { return nil, err } @@ -58,25 +58,25 @@ func (r *pluginRepo) FindByIDs(ctx context.Context, ids []id.PluginID) ([]*plugi } func (r *pluginRepo) Save(ctx context.Context, p *plugin.Plugin) error { - return rerror.ErrInternalBy(errors.New("read only")) + return rerror.ErrInternalByWithContext(ctx, errors.New("read only")) } func (r *pluginRepo) Remove(ctx context.Context, pid id.PluginID) error { - return rerror.ErrInternalBy(errors.New("read only")) + return rerror.ErrInternalByWithContext(ctx, errors.New("read only")) } var translationFileNameRegexp = regexp.MustCompile(`reearth_([a-zA-Z]+(?:-[a-zA-Z]+)?).yml`) -func readPluginManifest(fs afero.Fs, pid id.PluginID) (*manifest.Manifest, error) { +func readPluginManifest(ctx context.Context, fs afero.Fs, pid id.PluginID) (*manifest.Manifest, error) { base := filepath.Join(pluginDir, pid.String()) - translationMap, err := readPluginTranslation(fs, base) + translationMap, err := readPluginTranslation(ctx, fs, base) if err != nil { return nil, err } f, err := fs.Open(filepath.Join(base, manifestFilePath)) if err != nil { - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } defer func() { _ = f.Close() @@ -90,10 +90,10 @@ func readPluginManifest(fs afero.Fs, pid id.PluginID) (*manifest.Manifest, error return m, nil } -func readPluginTranslation(fs afero.Fs, base string) (manifest.TranslationMap, error) { +func readPluginTranslation(ctx context.Context, fs afero.Fs, base string) (manifest.TranslationMap, error) { d, err := afero.ReadDir(fs, base) if err != nil { - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } translationMap := manifest.TranslationMap{} @@ -108,7 +108,7 @@ func readPluginTranslation(fs afero.Fs, base string) (manifest.TranslationMap, e } langfile, err := fs.Open(filepath.Join(base, name)) if err != nil { - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } defer func() { _ = langfile.Close() diff --git a/server/internal/infrastructure/fs/property_schema.go b/server/internal/infrastructure/fs/property_schema.go index 3257c13e0c..e9819f960f 100644 --- a/server/internal/infrastructure/fs/property_schema.go +++ b/server/internal/infrastructure/fs/property_schema.go @@ -30,7 +30,7 @@ func (r *propertySchema) Filtered(f repo.SceneFilter) repo.PropertySchema { } func (r *propertySchema) FindByID(ctx context.Context, i id.PropertySchemaID) (*property.Schema, error) { - m, err := readPluginManifest(r.fs, i.Plugin()) + m, err := readPluginManifest(ctx, r.fs, i.Plugin()) if err != nil { return nil, err } @@ -66,17 +66,17 @@ func (r *propertySchema) FindByIDs(ctx context.Context, ids []id.PropertySchemaI } func (r *propertySchema) Save(ctx context.Context, p *property.Schema) error { - return rerror.ErrInternalBy(errors.New("read only")) + return rerror.ErrInternalByWithContext(ctx, errors.New("read only")) } func (r *propertySchema) SaveAll(ctx context.Context, p property.SchemaList) error { - return rerror.ErrInternalBy(errors.New("read only")) + return rerror.ErrInternalByWithContext(ctx, errors.New("read only")) } func (r *propertySchema) Remove(ctx context.Context, pid id.PropertySchemaID) error { - return rerror.ErrInternalBy(errors.New("read only")) + return rerror.ErrInternalByWithContext(ctx, errors.New("read only")) } func (r *propertySchema) RemoveAll(ctx context.Context, pid []id.PropertySchemaID) error { - return rerror.ErrInternalBy(errors.New("read only")) + return rerror.ErrInternalByWithContext(ctx, errors.New("read only")) } diff --git a/server/internal/infrastructure/gcs/file.go b/server/internal/infrastructure/gcs/file.go index 28d0fe8923..9453adfd2e 100644 --- a/server/internal/infrastructure/gcs/file.go +++ b/server/internal/infrastructure/gcs/file.go @@ -90,7 +90,7 @@ func (f *fileRepo) UploadAsset(ctx context.Context, file *file.File) (*url.URL, } func (f *fileRepo) RemoveAsset(ctx context.Context, u *url.URL) error { - log.Infof("gcs: asset deleted: %s", u) + log.Infofc(ctx, "gcs: asset deleted: %s", u) sn := getGCSObjectNameFromURL(f.base, u) if sn == "" { @@ -119,7 +119,7 @@ func (f *fileRepo) UploadPluginFile(ctx context.Context, pid id.PluginID, file * } func (f *fileRepo) RemovePlugin(ctx context.Context, pid id.PluginID) error { - log.Infof("gcs: plugin deleted: %s", pid) + log.Infofc(ctx, "gcs: plugin deleted: %s", pid) return f.deleteAll(ctx, path.Join(gcsPluginBasePath, pid.String())) } @@ -152,7 +152,7 @@ func (f *fileRepo) MoveBuiltScene(ctx context.Context, oldName, name string) err } func (f *fileRepo) RemoveBuiltScene(ctx context.Context, name string) error { - log.Infof("gcs: built scene deleted: %s", name) + log.Infofc(ctx, "gcs: built scene deleted: %s", name) sn := sanitize.Path(name + ".json") if sn == "" { @@ -179,8 +179,8 @@ func (f *fileRepo) read(ctx context.Context, filename string) (io.ReadCloser, er bucket, err := f.bucket(ctx) if err != nil { - log.Errorf("gcs: read bucket err: %+v\n", err) - return nil, rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: read bucket err: %+v\n", err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } reader, err := bucket.Object(filename).NewReader(ctx) @@ -188,8 +188,8 @@ func (f *fileRepo) read(ctx context.Context, filename string) (io.ReadCloser, er if errors.Is(err, storage.ErrObjectNotExist) { return nil, rerror.ErrNotFound } - log.Errorf("gcs: read err: %+v\n", err) - return nil, rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: read err: %+v\n", err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } return reader, nil @@ -202,13 +202,13 @@ func (f *fileRepo) upload(ctx context.Context, filename string, content io.Reade bucket, err := f.bucket(ctx) if err != nil { - log.Errorf("gcs: upload bucket err: %+v\n", err) - return 0, rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: upload bucket err: %+v\n", err) + return 0, rerror.ErrInternalByWithContext(ctx, err) } object := bucket.Object(filename) if err := object.Delete(ctx); err != nil && !errors.Is(err, storage.ErrObjectNotExist) { - log.Errorf("gcs: upload delete err: %+v\n", err) + log.Errorfc(ctx, "gcs: upload delete err: %+v\n", err) return 0, gateway.ErrFailedToUploadFile } @@ -217,12 +217,12 @@ func (f *fileRepo) upload(ctx context.Context, filename string, content io.Reade size, err := io.Copy(writer, content) if err != nil { - log.Errorf("gcs: upload err: %+v\n", err) + log.Errorfc(ctx, "gcs: upload err: %+v\n", err) return 0, gateway.ErrFailedToUploadFile } if err := writer.Close(); err != nil { - log.Errorf("gcs: upload close err: %+v\n", err) + log.Errorfc(ctx, "gcs: upload close err: %+v\n", err) return 0, gateway.ErrFailedToUploadFile } @@ -236,8 +236,8 @@ func (f *fileRepo) move(ctx context.Context, from, dest string) error { bucket, err := f.bucket(ctx) if err != nil { - log.Errorf("gcs: move bucket err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: move bucket err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } object := bucket.Object(from) @@ -246,13 +246,13 @@ func (f *fileRepo) move(ctx context.Context, from, dest string) error { if errors.Is(err, storage.ErrObjectNotExist) { return rerror.ErrNotFound } - log.Errorf("gcs: move copy err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: move copy err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } if err := object.Delete(ctx); err != nil { - log.Errorf("gcs: move delete err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: move delete err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil @@ -265,8 +265,8 @@ func (f *fileRepo) delete(ctx context.Context, filename string) error { bucket, err := f.bucket(ctx) if err != nil { - log.Errorf("gcs: delete bucket err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: delete bucket err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } object := bucket.Object(filename) @@ -275,8 +275,8 @@ func (f *fileRepo) delete(ctx context.Context, filename string) error { return nil } - log.Errorf("gcs: delete err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: delete err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } @@ -288,8 +288,8 @@ func (f *fileRepo) deleteAll(ctx context.Context, path string) error { bucket, err := f.bucket(ctx) if err != nil { - log.Errorf("gcs: deleteAll bucket err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: deleteAll bucket err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } it := bucket.Objects(ctx, &storage.Query{ @@ -302,12 +302,12 @@ func (f *fileRepo) deleteAll(ctx context.Context, path string) error { break } if err != nil { - log.Errorf("gcs: deleteAll next err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: deleteAll next err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } if err := bucket.Object(attrs.Name).Delete(ctx); err != nil { - log.Errorf("gcs: deleteAll err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "gcs: deleteAll err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } } return nil diff --git a/server/internal/infrastructure/marketplace/marketplace.go b/server/internal/infrastructure/marketplace/marketplace.go index 3278264ae8..a8199be2ca 100644 --- a/server/internal/infrastructure/marketplace/marketplace.go +++ b/server/internal/infrastructure/marketplace/marketplace.go @@ -7,8 +7,8 @@ import ( "strings" "github.com/reearth/reearth/server/pkg/id" - "github.com/reearth/reearth/server/pkg/log" "github.com/reearth/reearth/server/pkg/plugin/pluginpack" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/rerror" "golang.org/x/oauth2/clientcredentials" ) @@ -38,18 +38,18 @@ func (m *Marketplace) FetchPluginPackage(ctx context.Context, pid id.PluginID) ( return nil, err } - log.Infof("marketplace: downloading plugin package from \"%s\"", url) + log.Infofc(ctx, "marketplace: downloading plugin package from \"%s\"", url) req, err := http.NewRequest("GET", url, nil) if err != nil { - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } if m.secret != "" { req.Header.Set(secretHeader, m.secret) } res, err := m.client(ctx).Do(req) if err != nil { - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } defer func() { @@ -61,10 +61,14 @@ func (m *Marketplace) FetchPluginPackage(ctx context.Context, pid id.PluginID) ( } if res.StatusCode != http.StatusOK { - return nil, rerror.ErrInternalBy(fmt.Errorf("status code is %d", res.StatusCode)) + return nil, rerror.ErrInternalByWithContext(ctx, fmt.Errorf("status code is %d", res.StatusCode)) } - return pluginpack.PackageFromZip(res.Body, nil, pluginPackageSizeLimit) + p, err := pluginpack.PackageFromZip(res.Body, nil, pluginPackageSizeLimit) + if err != nil { + return nil, rerror.ErrInternalByWithContext(ctx, err) + } + return p, nil } func (m *Marketplace) NotifyDownload(ctx context.Context, pid id.PluginID) error { @@ -74,11 +78,11 @@ func (m *Marketplace) NotifyDownload(ctx context.Context, pid id.PluginID) error } url = url + "/download" - log.Infof("marketplace: notify donwload to \"%s\"", url) + log.Infofc(ctx, "marketplace: notify donwload to \"%s\"", url) req, err := http.NewRequest("POST", url, nil) if err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } if m.secret != "" { req.Header.Set(secretHeader, m.secret) @@ -86,7 +90,7 @@ func (m *Marketplace) NotifyDownload(ctx context.Context, pid id.PluginID) error res, err := m.client(ctx).Do(req) if err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } defer func() { @@ -94,7 +98,7 @@ func (m *Marketplace) NotifyDownload(ctx context.Context, pid id.PluginID) error }() if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNotFound { - return rerror.ErrInternalBy(fmt.Errorf("status code is %d", res.StatusCode)) + return rerror.ErrInternalByWithContext(ctx, fmt.Errorf("status code is %d", res.StatusCode)) } return nil } diff --git a/server/internal/infrastructure/mongo/asset.go b/server/internal/infrastructure/mongo/asset.go index 7fad24ff7a..43512468b0 100644 --- a/server/internal/infrastructure/mongo/asset.go +++ b/server/internal/infrastructure/mongo/asset.go @@ -89,7 +89,7 @@ func (r *Asset) TotalSizeByWorkspace(ctx context.Context, wid id.WorkspaceID) (i {"$group": bson.M{"_id": nil, "size": bson.M{"$sum": "$size"}}}, }) if err != nil { - return 0, rerror.ErrInternalBy(err) + return 0, rerror.ErrInternalByWithContext(ctx, err) } defer func() { _ = c.Close(ctx) @@ -104,7 +104,7 @@ func (r *Asset) TotalSizeByWorkspace(ctx context.Context, wid id.WorkspaceID) (i } var res resp if err := c.Decode(&res); err != nil { - return 0, rerror.ErrInternalBy(err) + return 0, rerror.ErrInternalByWithContext(ctx, err) } return res.Size, nil } @@ -134,7 +134,7 @@ func (r *Asset) paginate(ctx context.Context, filter any, sort *asset.SortType, c := mongodoc.NewAssetConsumer() pageInfo, err := r.client.Paginate(ctx, r.readFilter(filter), usort, pagination, c) if err != nil { - return nil, nil, rerror.ErrInternalBy(err) + return nil, nil, rerror.ErrInternalByWithContext(ctx, err) } return c.Result, pageInfo, nil @@ -143,7 +143,7 @@ func (r *Asset) paginate(ctx context.Context, filter any, sort *asset.SortType, func (r *Asset) find(ctx context.Context, filter any) ([]*asset.Asset, error) { c := mongodoc.NewAssetConsumer() if err2 := r.client.Find(ctx, r.readFilter(filter), c); err2 != nil { - return nil, rerror.ErrInternalBy(err2) + return nil, rerror.ErrInternalByWithContext(ctx, err2) } return c.Result, nil } diff --git a/server/internal/infrastructure/mongo/config.go b/server/internal/infrastructure/mongo/config.go index bfad7ff218..9ec64c3906 100644 --- a/server/internal/infrastructure/mongo/config.go +++ b/server/internal/infrastructure/mongo/config.go @@ -32,7 +32,7 @@ func (r *Config) LockAndLoad(ctx context.Context) (cfg *config.Config, err error cfgd := &mongodoc.ConfigDocument{} if err := r.client.FindOne(ctx, bson.M{}).Decode(cfgd); err != nil { if !errors.Is(err, mongo.ErrNilDocument) && !errors.Is(err, mongo.ErrNoDocuments) { - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, err) } } return cfgd.Model(), nil @@ -49,7 +49,7 @@ func (r *Config) Save(ctx context.Context, cfg *config.Config) error { bson.M{"$set": mongodoc.NewConfig(*cfg)}, (&options.UpdateOptions{}).SetUpsert(true), ); err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil @@ -68,7 +68,7 @@ func (r *Config) SaveAuth(ctx context.Context, cfg *config.Auth) error { }}, (&options.UpdateOptions{}).SetUpsert(true), ); err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil diff --git a/server/internal/infrastructure/mongo/dataset.go b/server/internal/infrastructure/mongo/dataset.go index b3010d27e5..77d6a68aeb 100644 --- a/server/internal/infrastructure/mongo/dataset.go +++ b/server/internal/infrastructure/mongo/dataset.go @@ -238,7 +238,7 @@ func (r *Dataset) FindGraph(ctx context.Context, did id.DatasetID, fields id.Dat cursor, err2 := r.client.Client().Aggregate(ctx, pipeline) if err2 != nil { - return nil, rerror.ErrInternalBy(err2) + return nil, rerror.ErrInternalByWithContext(ctx, err2) } defer func() { _ = cursor.Close(ctx) @@ -246,7 +246,7 @@ func (r *Dataset) FindGraph(ctx context.Context, did id.DatasetID, fields id.Dat doc := mongodoc.DatasetExtendedDocument{} if err2 := bson.Unmarshal(cursor.Current, &doc); err2 != nil { - return nil, rerror.ErrInternalBy(err2) + return nil, rerror.ErrInternalByWithContext(ctx, err2) } docs := make([]*mongodoc.DatasetExtendedDocument, 0, len(fields)) for i := 0; i < len(fields); i++ { @@ -265,11 +265,11 @@ func (r *Dataset) FindGraph(ctx context.Context, did id.DatasetID, fields id.Dat res := make(dataset.List, 0, len(docs)) for i, d := range docs { if i > 0 && i-1 != d.Depth { - return nil, rerror.ErrInternalBy(errors.New("invalid order")) + return nil, rerror.ErrInternalByWithContext(ctx, errors.New("invalid order")) } ds, err2 := d.DatasetDocument.Model() if err2 != nil { - return nil, rerror.ErrInternalBy(err2) + return nil, rerror.ErrInternalByWithContext(ctx, err2) } res = append(res, ds) } @@ -313,7 +313,7 @@ func (r *Dataset) RemoveByScene(ctx context.Context, sceneID id.SceneID) error { {Key: "scene", Value: sceneID.String()}, }) if err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } @@ -321,7 +321,7 @@ func (r *Dataset) RemoveByScene(ctx context.Context, sceneID id.SceneID) error { func (r *Dataset) find(ctx context.Context, dst dataset.List, filter interface{}) (dataset.List, error) { c := mongodoc.NewDatasetConsumer() if err2 := r.client.Find(ctx, r.readFilter(filter), c); err2 != nil { - return nil, rerror.ErrInternalBy(err2) + return nil, rerror.ErrInternalByWithContext(ctx, err2) } return c.Result, nil } @@ -338,7 +338,7 @@ func (r *Dataset) paginate(ctx context.Context, filter bson.M, pagination *useca c := mongodoc.NewDatasetConsumer() pageInfo, err := r.client.Paginate(ctx, r.readFilter(filter), nil, pagination, c) if err != nil { - return nil, nil, rerror.ErrInternalBy(err) + return nil, nil, rerror.ErrInternalByWithContext(ctx, err) } return c.Result, pageInfo, nil } diff --git a/server/internal/infrastructure/mongo/dataset_schema.go b/server/internal/infrastructure/mongo/dataset_schema.go index 1e58d3dc34..c31f5c02ef 100644 --- a/server/internal/infrastructure/mongo/dataset_schema.go +++ b/server/internal/infrastructure/mongo/dataset_schema.go @@ -155,7 +155,7 @@ func (r *DatasetSchema) RemoveByScene(ctx context.Context, sceneID id.SceneID) e if _, err := r.client.Client().DeleteMany(ctx, bson.M{ "scene": sceneID.String(), }); err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } @@ -180,7 +180,7 @@ func (r *DatasetSchema) paginate(ctx context.Context, filter bson.M, pagination c := mongodoc.NewDatasetSchemaConsumer() pageInfo, err := r.client.Paginate(ctx, r.readFilter(filter), nil, pagination, c) if err != nil { - return nil, nil, rerror.ErrInternalBy(err) + return nil, nil, rerror.ErrInternalByWithContext(ctx, err) } return c.Result, pageInfo, nil } diff --git a/server/internal/infrastructure/mongo/layer.go b/server/internal/infrastructure/mongo/layer.go index c4e38c832d..25cd2a913d 100644 --- a/server/internal/infrastructure/mongo/layer.go +++ b/server/internal/infrastructure/mongo/layer.go @@ -263,7 +263,7 @@ func (r *Layer) RemoveByScene(ctx context.Context, sceneID id.SceneID) error { } _, err := r.client.Client().DeleteMany(ctx, filter) if err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } diff --git a/server/internal/infrastructure/mongo/lock.go b/server/internal/infrastructure/mongo/lock.go index 29a27d8df5..0034119235 100644 --- a/server/internal/infrastructure/mongo/lock.go +++ b/server/internal/infrastructure/mongo/lock.go @@ -40,18 +40,18 @@ func (r *Lock) Lock(ctx context.Context, name string) error { } lockID := uuid.NewString() - log.Infof("lock: trying to lock: id=%s, name=%s, host=%s", name, lockID, r.hostid) + log.Infofc(ctx, "lock: trying to lock: id=%s, name=%s, host=%s", name, lockID, r.hostid) if err := retry.Do( func() error { return r.l.XLock(ctx, name, lockID, r.details()) }, retry.RetryIf(func(err error) bool { return errors.Is(err, lock.ErrAlreadyLocked) }), ); err != nil { - log.Infof("lock: failed to lock: name=%s, id=%s, host=%s, err=%s", name, lockID, r.hostid, err) + log.Infofc(ctx, "lock: failed to lock: name=%s, id=%s, host=%s, err=%s", name, lockID, r.hostid, err) return repo.ErrFailedToLock } r.setLockID(name, lockID) - log.Infof("lock: locked: name=%s, id=%s, host=%s", name, lockID, r.hostid) + log.Infofc(ctx, "lock: locked: name=%s, id=%s, host=%s", name, lockID, r.hostid) return nil } @@ -62,11 +62,11 @@ func (r *Lock) Unlock(ctx context.Context, name string) error { } if _, err := r.l.Unlock(ctx, lockID); err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } r.deleteLockID(name) - log.Infof("lock: unlocked: name=%s, id=%s, host=%s", name, lockID, r.hostid) + log.Infofc(ctx, "lock: unlocked: name=%s, id=%s, host=%s", name, lockID, r.hostid) return nil } diff --git a/server/internal/infrastructure/mongo/migration/201217132559_add_scene_widget_id.go b/server/internal/infrastructure/mongo/migration/201217132559_add_scene_widget_id.go index bcd2e94bba..f6b17b9db4 100644 --- a/server/internal/infrastructure/mongo/migration/201217132559_add_scene_widget_id.go +++ b/server/internal/infrastructure/mongo/migration/201217132559_add_scene_widget_id.go @@ -3,9 +3,9 @@ package migration import ( "context" - "github.com/labstack/gommon/log" "github.com/reearth/reearth/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth/server/pkg/id" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "go.mongodb.org/mongo-driver/bson" ) @@ -20,7 +20,7 @@ func AddSceneWidgetId(ctx context.Context, c DBClient) error { ids := make([]string, 0, len(rows)) newRows := make([]interface{}, 0, len(rows)) - log.Infof("migration: AddSceneWidgetId: hit scenes: %d\n", len(rows)) + log.Infofc(ctx, "migration: AddSceneWidgetId: hit scenes: %d\n", len(rows)) for _, row := range rows { var doc mongodoc.SceneDocument diff --git a/server/internal/infrastructure/mongo/migration/201217193948_add_scene_default_tile.go b/server/internal/infrastructure/mongo/migration/201217193948_add_scene_default_tile.go index 81274a36b2..4fbf7598b2 100644 --- a/server/internal/infrastructure/mongo/migration/201217193948_add_scene_default_tile.go +++ b/server/internal/infrastructure/mongo/migration/201217193948_add_scene_default_tile.go @@ -44,12 +44,12 @@ func AddSceneDefaultTile(ctx context.Context, c DBClient) error { }, } - log.Infof("migration: AddSceneDefaultTile: filter: %+v\n", filter) + log.Infofc(ctx, "migration: AddSceneDefaultTile: filter: %+v\n", filter) return col.Find(ctx, filter, &mongodoc.PropertyBatchConsumer{ Size: 1000, Callback: func(properties []*property.Property) error { - log.Infof("migration: AddSceneDefaultTile: hit properties: %d\n", len(properties)) + log.Infofc(ctx, "migration: AddSceneDefaultTile: hit properties: %d\n", len(properties)) for _, p := range properties { g := p.GetOrCreateGroupList(scenePropertySchema, property.PointItemBySchema(id.PropertySchemaGroupID("tiles"))) diff --git a/server/internal/infrastructure/mongo/migration/210310145844_remove_preview_token.go b/server/internal/infrastructure/mongo/migration/210310145844_remove_preview_token.go index ecc4fb298f..f72e33f4c2 100644 --- a/server/internal/infrastructure/mongo/migration/210310145844_remove_preview_token.go +++ b/server/internal/infrastructure/mongo/migration/210310145844_remove_preview_token.go @@ -3,7 +3,7 @@ package migration import ( "context" - "github.com/labstack/gommon/log" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "go.mongodb.org/mongo-driver/bson" ) @@ -18,7 +18,7 @@ func RemovePreviewToken(ctx context.Context, c DBClient) error { ids := make([]string, 0, len(rows)) newRows := make([]interface{}, 0, len(rows)) - log.Infof("migration: RemoveProjectPreviewToken: hit projects: %d\n", len(rows)) + log.Infofc(ctx, "migration: RemoveProjectPreviewToken: hit projects: %d\n", len(rows)) for _, row := range rows { doc := bson.M{} diff --git a/server/internal/infrastructure/mongo/migration/210730175108_add_scene_align_system.go b/server/internal/infrastructure/mongo/migration/210730175108_add_scene_align_system.go index a98bd08b27..1752f4ab8b 100644 --- a/server/internal/infrastructure/mongo/migration/210730175108_add_scene_align_system.go +++ b/server/internal/infrastructure/mongo/migration/210730175108_add_scene_align_system.go @@ -3,12 +3,12 @@ package migration import ( "context" - "github.com/labstack/gommon/log" "github.com/reearth/reearth/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth/server/pkg/builtin" "github.com/reearth/reearth/server/pkg/id" "github.com/reearth/reearth/server/pkg/plugin" "github.com/reearth/reearth/server/pkg/scene" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "go.mongodb.org/mongo-driver/bson" ) @@ -22,7 +22,7 @@ func AddSceneAlignSystem(ctx context.Context, c DBClient) error { ids := make([]string, 0, len(rows)) newRows := make([]interface{}, 0, len(rows)) - log.Infof("migration: AddSceneAlignSystem: hit scenes: %d\n", len(rows)) + log.Infofc(ctx, "migration: AddSceneAlignSystem: hit scenes: %d\n", len(rows)) for _, row := range rows { var doc mongodoc.SceneDocument diff --git a/server/internal/infrastructure/mongo/migration/220214180713_split_schema_of_properties.go b/server/internal/infrastructure/mongo/migration/220214180713_split_schema_of_properties.go index 8b7bbde8b6..93aacd5c49 100644 --- a/server/internal/infrastructure/mongo/migration/220214180713_split_schema_of_properties.go +++ b/server/internal/infrastructure/mongo/migration/220214180713_split_schema_of_properties.go @@ -3,9 +3,9 @@ package migration import ( "context" - "github.com/labstack/gommon/log" "github.com/reearth/reearth/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth/server/pkg/id" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "go.mongodb.org/mongo-driver/bson" ) @@ -21,7 +21,7 @@ func SplitSchemaOfProperties(ctx context.Context, c DBClient) error { ids := make([]string, 0, len(rows)) newRows := make([]interface{}, 0, len(rows)) - log.Infof("migration: SplitSchemaOfProperties: hit properties: %d\n", len(rows)) + log.Infofc(ctx, "migration: SplitSchemaOfProperties: hit properties: %d\n", len(rows)) for _, row := range rows { var doc mongodoc.PropertyDocument diff --git a/server/internal/infrastructure/mongo/migration/220309174648_add_scene_field_to_property_schema.go b/server/internal/infrastructure/mongo/migration/220309174648_add_scene_field_to_property_schema.go index cded96a344..19d2b8ac4f 100644 --- a/server/internal/infrastructure/mongo/migration/220309174648_add_scene_field_to_property_schema.go +++ b/server/internal/infrastructure/mongo/migration/220309174648_add_scene_field_to_property_schema.go @@ -3,9 +3,9 @@ package migration import ( "context" - "github.com/labstack/gommon/log" "github.com/reearth/reearth/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth/server/pkg/id" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "go.mongodb.org/mongo-driver/bson" ) @@ -19,7 +19,7 @@ func AddSceneFieldToPropertySchema(ctx context.Context, c DBClient) error { ids := make([]string, 0, len(rows)) newRows := make([]interface{}, 0, len(rows)) - log.Infof("migration: AddSceneFieldToPropertySchema: hit property schemas: %d\n", len(rows)) + log.Infofc(ctx, "migration: AddSceneFieldToPropertySchema: hit property schemas: %d\n", len(rows)) for _, row := range rows { var doc mongodoc.PropertySchemaDocument diff --git a/server/internal/infrastructure/mongo/migration/221028204300_move_terrain_properties.go b/server/internal/infrastructure/mongo/migration/221028204300_move_terrain_properties.go index 728ed71bc2..d14632083b 100644 --- a/server/internal/infrastructure/mongo/migration/221028204300_move_terrain_properties.go +++ b/server/internal/infrastructure/mongo/migration/221028204300_move_terrain_properties.go @@ -3,9 +3,9 @@ package migration import ( "context" - "github.com/labstack/gommon/log" "github.com/reearth/reearth/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth/server/pkg/property" + "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "github.com/samber/lo" "go.mongodb.org/mongo-driver/bson" @@ -52,7 +52,7 @@ func MoveTerrainProperties(ctx context.Context, c DBClient) error { ids := make([]string, 0, len(rows)) newRows := make([]interface{}, 0, len(rows)) - log.Infof("migration: MoveTerrainProperties: hit properties: %d\n", len(rows)) + log.Infofc(ctx, "migration: MoveTerrainProperties: hit properties: %d\n", len(rows)) for _, row := range rows { var doc mongodoc.PropertyDocument diff --git a/server/internal/infrastructure/mongo/project.go b/server/internal/infrastructure/mongo/project.go index 821017e87c..28256f82e9 100644 --- a/server/internal/infrastructure/mongo/project.go +++ b/server/internal/infrastructure/mongo/project.go @@ -2,7 +2,6 @@ package mongo import ( "context" - "errors" "go.mongodb.org/mongo-driver/bson" @@ -10,7 +9,6 @@ import ( "github.com/reearth/reearth/server/internal/usecase/repo" "github.com/reearth/reearth/server/pkg/id" "github.com/reearth/reearth/server/pkg/project" - "github.com/reearth/reearthx/log" "github.com/reearth/reearthx/mongox" "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/usecasex" @@ -90,11 +88,7 @@ func (r *Project) FindByPublicName(ctx context.Context, name string) (*project.P }, } - res, err := r.findOneWithoutReadFilter(ctx, f) - if errors.Is(err, rerror.ErrNotFound) { - log.Infof("mongo: project.FindByPublicName: name=%s err=%v filter=%v q=%#v", name, err, r.f.Readable.Strings(), f) - } - return res, err + return r.findOneWithoutReadFilter(ctx, f) } func (r *Project) CountByWorkspace(ctx context.Context, ws id.WorkspaceID) (int, error) { @@ -158,7 +152,7 @@ func (r *Project) paginate(ctx context.Context, filter bson.M, pagination *useca c := mongodoc.NewProjectConsumer() pageInfo, err := r.client.Paginate(ctx, r.readFilter(filter), nil, pagination, c) if err != nil { - return nil, nil, rerror.ErrInternalBy(err) + return nil, nil, rerror.ErrInternalByWithContext(ctx, err) } return c.Result, pageInfo, nil } diff --git a/server/internal/infrastructure/mongo/property.go b/server/internal/infrastructure/mongo/property.go index def374be95..6e9265dbb6 100644 --- a/server/internal/infrastructure/mongo/property.go +++ b/server/internal/infrastructure/mongo/property.go @@ -189,7 +189,7 @@ func (r *Property) RemoveByScene(ctx context.Context, sceneID id.SceneID) error "scene": sceneID.String(), }) if err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } diff --git a/server/internal/infrastructure/mongo/scene_lock.go b/server/internal/infrastructure/mongo/scene_lock.go index c176638cc2..694f523691 100644 --- a/server/internal/infrastructure/mongo/scene_lock.go +++ b/server/internal/infrastructure/mongo/scene_lock.go @@ -60,7 +60,7 @@ func (r *SceneLock) SaveLock(ctx context.Context, sceneID id.SceneID, lock scene }, &options.UpdateOptions{ Upsert: &upsert, }); err2 != nil { - return rerror.ErrInternalBy(err2) + return rerror.ErrInternalByWithContext(ctx, err2) } return nil } @@ -68,7 +68,7 @@ func (r *SceneLock) SaveLock(ctx context.Context, sceneID id.SceneID, lock scene func (r *SceneLock) ReleaseAllLock(ctx context.Context) error { if _, err2 := r.client.Client().DeleteMany(ctx, bson.D{}); err2 != nil { if err2 != mongo.ErrNilDocument && err2 != mongo.ErrNoDocuments { - return rerror.ErrInternalBy(err2) + return rerror.ErrInternalByWithContext(ctx, err2) } } return nil diff --git a/server/internal/infrastructure/mongo/tag.go b/server/internal/infrastructure/mongo/tag.go index 313f15d258..271420525c 100644 --- a/server/internal/infrastructure/mongo/tag.go +++ b/server/internal/infrastructure/mongo/tag.go @@ -160,7 +160,7 @@ func (r *Tag) RemoveByScene(ctx context.Context, sceneID id.SceneID) error { "scene": sceneID.String(), }) if err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil } diff --git a/server/internal/infrastructure/s3/s3.go b/server/internal/infrastructure/s3/s3.go index 4a98079dc0..673aeeb8e3 100644 --- a/server/internal/infrastructure/s3/s3.go +++ b/server/internal/infrastructure/s3/s3.go @@ -99,7 +99,7 @@ func (f *fileRepo) UploadAsset(ctx context.Context, file *file.File) (*url.URL, } func (f *fileRepo) RemoveAsset(ctx context.Context, u *url.URL) error { - log.Infof("s3: asset deleted: %s", u) + log.Infofc(ctx, "s3: asset deleted: %s", u) sn := getObjectNameFromURL(f.base, u) if sn == "" { @@ -128,7 +128,7 @@ func (f *fileRepo) UploadPluginFile(ctx context.Context, pid id.PluginID, file * } func (f *fileRepo) RemovePlugin(ctx context.Context, pid id.PluginID) error { - log.Infof("s3: plugin deleted: %s", pid) + log.Infofc(ctx, "s3: plugin deleted: %s", pid) return f.deleteAll(ctx, path.Join(pluginBasePath, pid.String())) } @@ -161,7 +161,7 @@ func (f *fileRepo) MoveBuiltScene(ctx context.Context, oldName, name string) err } func (f *fileRepo) RemoveBuiltScene(ctx context.Context, name string) error { - log.Infof("s3: built scene deleted: %s", name) + log.Infofc(ctx, "s3: built scene deleted: %s", name) sn := sanitize.Path(name + ".json") if sn == "" { @@ -182,8 +182,7 @@ func (f *fileRepo) read(ctx context.Context, filename string) (io.ReadCloser, er Key: aws.String(filename), }) if err != nil { - log.Errorf("s3: read err: %+v\n", err) - return nil, rerror.ErrInternalBy(err) + return nil, rerror.ErrInternalByWithContext(ctx, fmt.Errorf("s3: read err: %+v", err)) } return obj.Body, nil @@ -199,7 +198,7 @@ func (f *fileRepo) upload(ctx context.Context, filename string, content io.Reade ba, err := io.ReadAll(content) if err != nil { - return 0, rerror.ErrInternalBy(err) + return 0, rerror.ErrInternalByWithContext(ctx, err) } body := bytes.NewReader(ba) @@ -211,7 +210,7 @@ func (f *fileRepo) upload(ctx context.Context, filename string, content io.Reade ContentLength: body.Size(), }) if err != nil { - log.Errorf("s3: upload err: %+v\n", err) + log.Errorfc(ctx, "s3: upload err: %v", err) return 0, gateway.ErrFailedToUploadFile } @@ -220,7 +219,7 @@ func (f *fileRepo) upload(ctx context.Context, filename string, content io.Reade Key: aws.String(filename), }) if err != nil { - log.Errorf("s3: check file size after upload err: %+v\n", err) + log.Errorfc(ctx, "s3: check file size after upload err: %v", err) return 0, gateway.ErrFailedToUploadFile } @@ -239,8 +238,8 @@ func (f *fileRepo) copy(ctx context.Context, from, dest string) error { Key: aws.String(dest), }) if err != nil { - log.Errorf("s3: copy err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "s3: copy err: %+v\n", err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil @@ -274,8 +273,8 @@ func (f *fileRepo) delete(ctx context.Context, filename string) error { Key: aws.String(filename), }) if err != nil { - log.Errorf("s3: delete err: %+v\n", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "s3: delete err: %v", err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil @@ -291,8 +290,8 @@ func (f *fileRepo) deleteAll(ctx context.Context, path string) error { Prefix: aws.String(path), }) if err != nil { - log.Errorf("s3: Unable to list object for delete %v", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "s3: unable to list object for delete %v", err) + return rerror.ErrInternalByWithContext(ctx, err) } keys := lo.Map(l.Contents, func(obj types.Object, _ int) types.ObjectIdentifier { @@ -305,8 +304,8 @@ func (f *fileRepo) deleteAll(ctx context.Context, path string) error { }, }) if err != nil { - log.Errorf("s3: Unable to delete object %v", err) - return rerror.ErrInternalBy(err) + log.Errorfc(ctx, "s3: unable to delete object: %v", err) + return rerror.ErrInternalByWithContext(ctx, err) } return nil diff --git a/server/internal/usecase/gateway/authenticator.go b/server/internal/usecase/gateway/authenticator.go index 86a30b6a76..7a2c6ad0b8 100644 --- a/server/internal/usecase/gateway/authenticator.go +++ b/server/internal/usecase/gateway/authenticator.go @@ -1,5 +1,7 @@ package gateway +import "context" + type AuthenticatorUpdateUserParam struct { ID string Name *string @@ -15,5 +17,5 @@ type AuthenticatorUser struct { } type Authenticator interface { - UpdateUser(AuthenticatorUpdateUserParam) (AuthenticatorUser, error) + UpdateUser(context.Context, AuthenticatorUpdateUserParam) (AuthenticatorUser, error) } diff --git a/server/internal/usecase/interactor/dataset.go b/server/internal/usecase/interactor/dataset.go index cfe4658385..5608529c7d 100644 --- a/server/internal/usecase/interactor/dataset.go +++ b/server/internal/usecase/interactor/dataset.go @@ -392,7 +392,7 @@ func (i *Dataset) GraphFetch(ctx context.Context, id id.DatasetID, depth int, _ res = append(res, d) next, done = it.Next(d) if next.IsNil() { - return nil, rerror.ErrInternalBy(errors.New("next id is nil")) + return nil, rerror.ErrInternalByWithContext(ctx, errors.New("next id is nil")) } if done { break @@ -422,7 +422,7 @@ func (i *Dataset) GraphFetchSchema(ctx context.Context, id id.DatasetSchemaID, d res = append(res, d) next, done = it.Next(d) if next.IsNil() { - return nil, rerror.ErrInternalBy(errors.New("next id is nil")) + return nil, rerror.ErrInternalByWithContext(ctx, errors.New("next id is nil")) } if done { break diff --git a/server/internal/usecase/interactor/plugin_common.go b/server/internal/usecase/interactor/plugin_common.go index 52beffaaf5..9f09dfb146 100644 --- a/server/internal/usecase/interactor/plugin_common.go +++ b/server/internal/usecase/interactor/plugin_common.go @@ -28,7 +28,7 @@ func (i *pluginCommon) SavePluginPack(ctx context.Context, p *pluginpack.Package for { f, err := p.Files.Next() if err != nil { - log.Errorf("failed to read a plugin file (%s): %s", id, err) + log.Errorfc(ctx, "failed to read a plugin file (%s): %s", id, err) return interfaces.ErrInvalidPluginPackage } @@ -38,12 +38,12 @@ func (i *pluginCommon) SavePluginPack(ctx context.Context, p *pluginpack.Package read = true if err := i.file.UploadPluginFile(ctx, p.Manifest.Plugin.ID(), f); err != nil { - return rerror.ErrInternalBy(err) + return rerror.ErrInternalByWithContext(ctx, err) } } if !read { - log.Errorf("no plugin files (%s)", id) + log.Errorfc(ctx, "no plugin files (%s)", id) return interfaces.ErrInvalidPluginPackage } diff --git a/server/internal/usecase/interactor/plugin_upload.go b/server/internal/usecase/interactor/plugin_upload.go index 67ab6dd788..688ba17393 100644 --- a/server/internal/usecase/interactor/plugin_upload.go +++ b/server/internal/usecase/interactor/plugin_upload.go @@ -66,7 +66,11 @@ func (i *Plugin) UploadFromRemote(ctx context.Context, u *url.URL, sid id.SceneI p, err := pluginpack.PackageFromZip(res.Body, &sid, pluginPackageSizeLimit) if err != nil { _ = res.Body.Close() - return nil, nil, interfaces.ErrInvalidPluginPackage + return nil, nil, &rerror.Error{ + Label: interfaces.ErrInvalidPluginPackage, + Err: err, + Separate: true, + } } return i.upload(ctx, p, sid, operator) diff --git a/server/internal/usecase/interactor/published.go b/server/internal/usecase/interactor/published.go index f05558a737..d5008eff15 100644 --- a/server/internal/usecase/interactor/published.go +++ b/server/internal/usecase/interactor/published.go @@ -47,19 +47,19 @@ func NewPublishedWithURL(project repo.Project, file gateway.File, indexHTMLURL * } res, err := http.DefaultClient.Do(req) if err != nil { - log.Errorf("published index: conn err: %s", err) + log.Errorfc(c, "published index: conn err: %s", err) return "", errors.New("failed to fetch HTML") } defer func() { _ = res.Body.Close() }() if res.StatusCode >= 300 { - log.Errorf("published index: status err: %d", res.StatusCode) + log.Errorfc(c, "published index: status err: %d", res.StatusCode) return "", errors.New("failed to fetch HTML") } str, err := io.ReadAll(res.Body) if err != nil { - log.Errorf("published index: read err: %s", err) + log.Errorfc(c, "published index: read err: %s", err) return "", errors.New("failed to fetch HTML") } return string(str), nil diff --git a/server/internal/usecase/interactor/user.go b/server/internal/usecase/interactor/user.go index 2883f69e42..f7f3decd7c 100644 --- a/server/internal/usecase/interactor/user.go +++ b/server/internal/usecase/interactor/user.go @@ -330,7 +330,7 @@ func (i *User) UpdateMe(ctx context.Context, p interfaces.UpdateMeParam, operato if a.Provider != "auth0" { continue } - if _, err := i.authenticator.UpdateUser(gateway.AuthenticatorUpdateUserParam{ + if _, err := i.authenticator.UpdateUser(ctx, gateway.AuthenticatorUpdateUserParam{ ID: a.Sub, Name: p.Name, Email: p.Email, diff --git a/server/pkg/log/gceformatter.go b/server/pkg/log/gceformatter.go deleted file mode 100644 index 0df77cc26a..0000000000 --- a/server/pkg/log/gceformatter.go +++ /dev/null @@ -1,123 +0,0 @@ -package log - -// https://github.com/znly/logrus-gce with some modifications -// Apache License 2.0 - -import ( - "encoding/json" - "errors" - "fmt" - "runtime" - "strings" - "sync" - "time" - - "github.com/sirupsen/logrus" -) - -type severity string - -const ( - severityDEBUG severity = "DEBUG" - severityINFO severity = "INFO" - severityWARNING severity = "WARNING" - severityERROR severity = "ERROR" - severityCRITICAL severity = "CRITICAL" - severityALERT severity = "ALERT" -) - -var ( - levelsLogrusToGCE = map[logrus.Level]severity{ - logrus.DebugLevel: severityDEBUG, - logrus.InfoLevel: severityINFO, - logrus.WarnLevel: severityWARNING, - logrus.ErrorLevel: severityERROR, - logrus.FatalLevel: severityCRITICAL, - logrus.PanicLevel: severityALERT, - } -) - -var ( - stackSkips = map[logrus.Level]int{} - stackSkipsMu = sync.RWMutex{} -) - -var ( - ErrSkipNotFound = errors.New("could not find skips for log level") -) - -func getSkipLevel(level logrus.Level) (int, error) { - stackSkipsMu.RLock() - if skip, ok := stackSkips[level]; ok { - defer stackSkipsMu.RUnlock() - return skip, nil - } - stackSkipsMu.RUnlock() - - stackSkipsMu.Lock() - defer stackSkipsMu.Unlock() - if skip, ok := stackSkips[level]; ok { - return skip, nil - } - - // detect until we escape logrus back to the client package - // skip out of runtime and logrusgce package, hence 3 - stackSkipsCallers := make([]uintptr, 20) - runtime.Callers(3, stackSkipsCallers) - for i, pc := range stackSkipsCallers { - f := runtime.FuncForPC(pc) - if strings.HasPrefix(f.Name(), "github.com/sirupsen/logrus") { - continue - } - stackSkips[level] = i + 1 - return i + 1, nil - } - return 0, ErrSkipNotFound -} - -type GCEFormatter struct { - withSourceInfo bool -} - -func NewGCEFormatter(withSourceInfo bool) *GCEFormatter { - return &GCEFormatter{withSourceInfo: withSourceInfo} -} - -func (f *GCEFormatter) Format(entry *logrus.Entry) ([]byte, error) { - data := make(logrus.Fields, len(entry.Data)+3) - for k, v := range entry.Data { - switch v := v.(type) { - case error: - // Otherwise errors are ignored by `encoding/json` - // https://github.com/Sirupsen/logrus/issues/137 - data[k] = v.Error() - default: - data[k] = v - } - } - - data["time"] = entry.Time.Format(time.RFC3339Nano) - data["severity"] = levelsLogrusToGCE[entry.Level] - data["logMessage"] = entry.Message - - if f.withSourceInfo { - skip, err := getSkipLevel(entry.Level) - if err != nil { - return nil, err - } - if pc, file, line, ok := runtime.Caller(skip); ok { - f := runtime.FuncForPC(pc) - data["sourceLocation"] = map[string]interface{}{ - "file": file, - "line": line, - "functionName": f.Name(), - } - } - } - - serialized, err := json.Marshal(data) - if err != nil { - return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) - } - return append(serialized, '\n'), nil -} diff --git a/server/pkg/log/log.go b/server/pkg/log/log.go deleted file mode 100644 index a42a6f0021..0000000000 --- a/server/pkg/log/log.go +++ /dev/null @@ -1,108 +0,0 @@ -package log - -import ( - "os" - - "github.com/sirupsen/logrus" -) - -func init() { - gcp, _ := os.LookupEnv("GOOGLE_CLOUD_PROJECT") - logrus.SetLevel(logrus.InfoLevel) - if gcp != "" { - logrus.SetFormatter(NewGCEFormatter(false)) - } else { - logrus.SetFormatter(&logrus.TextFormatter{ - DisableColors: false, - FullTimestamp: true, - }) - } -} - -func Tracef(format string, args ...interface{}) { - logrus.Tracef(format, args...) -} - -func Debugf(format string, args ...interface{}) { - logrus.Debugf(format, args...) -} - -func Infof(format string, args ...interface{}) { - logrus.Infof(format, args...) -} - -func Printf(format string, args ...interface{}) { - logrus.Printf(format, args...) -} - -func Warnf(format string, args ...interface{}) { - logrus.Warnf(format, args...) -} - -func Errorf(format string, args ...interface{}) { - logrus.Errorf(format, args...) -} - -func Fatalf(format string, args ...interface{}) { - logrus.Fatalf(format, args...) -} - -func Trace(args ...interface{}) { - logrus.Trace(args...) -} - -func Debug(args ...interface{}) { - logrus.Debug(args...) -} - -func Info(args ...interface{}) { - logrus.Info(args...) -} - -func Print(args ...interface{}) { - logrus.Print(args...) -} - -func Warn(args ...interface{}) { - logrus.Warn(args...) -} - -func Error(args ...interface{}) { - logrus.Error(args...) -} - -func Fatal(args ...interface{}) { - logrus.Fatal(args...) -} - -func Traceln(args ...interface{}) { - logrus.Traceln(args...) -} - -func Debugln(args ...interface{}) { - logrus.Debugln(args...) -} - -func Infoln(args ...interface{}) { - logrus.Infoln(args...) -} - -func Println(args ...interface{}) { - logrus.Println(args...) -} - -func Warnln(args ...interface{}) { - logrus.Warnln(args...) -} - -func Errorln(args ...interface{}) { - logrus.Errorln(args...) -} - -func Fatalln(args ...interface{}) { - logrus.Fatalln(args...) -} - -func Panicf(format string, args ...interface{}) { - logrus.Panicf(format, args...) -} diff --git a/server/pkg/plugin/pluginpack/package.go b/server/pkg/plugin/pluginpack/package.go index 054c63da98..dd549b33b0 100644 --- a/server/pkg/plugin/pluginpack/package.go +++ b/server/pkg/plugin/pluginpack/package.go @@ -3,6 +3,7 @@ package pluginpack import ( "archive/zip" "bytes" + "fmt" "io" "path" "path/filepath" @@ -79,7 +80,7 @@ func readTranslation(fs *zip.Reader, base string) (manifest.TranslationMap, erro } langfile, err := f.Open() if err != nil { - return nil, rerror.ErrInternalBy(err) + return nil, fmt.Errorf("failed to open translation file: %w", err) } defer func() { _ = langfile.Close() diff --git a/server/pkg/scene/sceneops/plugin_installer.go b/server/pkg/scene/sceneops/plugin_installer.go index a881cdc079..9b5279b58a 100644 --- a/server/pkg/scene/sceneops/plugin_installer.go +++ b/server/pkg/scene/sceneops/plugin_installer.go @@ -31,27 +31,27 @@ func (s PluginInstaller) InstallPluginFromRepository(pluginID scene.PluginID) er // for _, s := range manifest.ExtensionSchema { // err = i.propertySchemaRepo.Save(&s) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // } // err = i.pluginRepo.Save(plugin) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // // Download and extract plugin files to storage // data, err := i.pluginRepositoryRepo.Data(inp.Name, inp.Version) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // _, err = i.fileRepo.UploadAndExtractPluginFiles(data, plugin) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } @@ -78,7 +78,7 @@ func (s PluginInstaller) InstallPluginFromRepository(pluginID scene.PluginID) er // Public(inp.Public). // Build() // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } @@ -86,7 +86,7 @@ func (s PluginInstaller) InstallPluginFromRepository(pluginID scene.PluginID) er // if manifest.Schema != nil { // err = i.propertySchemaRepo.Save(manifest.Schema) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // } @@ -94,27 +94,27 @@ func (s PluginInstaller) InstallPluginFromRepository(pluginID scene.PluginID) er // for _, s := range manifest.ExtensionSchema { // err = i.propertySchemaRepo.Save(&s) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // } // err = i.pluginRepo.Save(plugin) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // // Download and extract plugin files to storage // data, err := i.pluginRepositoryRepo.Data(inp.Name, inp.Version) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } // _, err = i.fileRepo.UploadAndExtractPluginFiles(data, plugin) // if err != nil { - // i.output.Upload(nil, rerror.ErrInternalBy(err)) + // i.output.Upload(nil, rerror.ErrInternalByWithContext(ctx, err)) // return // } diff --git a/server/pkg/scene/sceneops/plugin_migrator.go b/server/pkg/scene/sceneops/plugin_migrator.go index b78def084c..a3ada84e8a 100644 --- a/server/pkg/scene/sceneops/plugin_migrator.go +++ b/server/pkg/scene/sceneops/plugin_migrator.go @@ -34,7 +34,7 @@ var ( func (s *PluginMigrator) MigratePlugins(ctx context.Context, sc *scene.Scene, oldPluginID, newPluginID plugin.ID) (MigratePluginsResult, error) { if s == nil { - return MigratePluginsResult{}, rerror.ErrInternalBy(errors.New("scene is nil")) + return MigratePluginsResult{}, rerror.ErrInternalByWithContext(ctx, errors.New("scene is nil")) } // should be same plugin but different version