Compare commits
2 Commits
2023.10.21
...
2023.10.22
Author | SHA1 | Date | |
---|---|---|---|
6e4bf2f025 | |||
22a3326be9 |
@ -2,7 +2,6 @@ package module
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"forge.cadoles.com/arcad/edge/pkg/app"
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
@ -20,34 +19,17 @@ func (m *LifecycleModule) Export(export *goja.Object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *LifecycleModule) OnInit(ctx context.Context, rt *goja.Runtime) (err error) {
|
func (m *LifecycleModule) OnInit(ctx context.Context, rt *goja.Runtime) (err error) {
|
||||||
call, ok := goja.AssertFunction(rt.Get("onInit"))
|
_, ok := goja.AssertFunction(rt.Get("onInit"))
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Warn(ctx, "could not find onInit() function")
|
logger.Warn(ctx, "could not find onInit() function")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
if _, err := rt.RunString("setTimeout(onInit, 0)"); err != nil {
|
||||||
if recovered := recover(); recovered != nil {
|
return errors.WithStack(err)
|
||||||
revoveredErr, ok := recovered.(error)
|
|
||||||
if ok {
|
|
||||||
logger.Error(ctx, "recovered runtime error", logger.CapturedE(errors.WithStack(revoveredErr)))
|
|
||||||
|
|
||||||
err = errors.WithStack(app.ErrUnknownError)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
panic(recovered)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
logger.Debug(ctx, "executing app onInit() function")
|
|
||||||
start := time.Now()
|
|
||||||
call(nil)
|
|
||||||
duration := time.Since(start)
|
|
||||||
logger.Debug(ctx, "executed app onInit() function", logger.F("duration", duration.String()))
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func (s *BlobStore) OpenBucket(ctx context.Context, name string) (storage.BlobBu
|
|||||||
func (s *BlobStore) call(ctx context.Context, serviceMethod string, args any, reply any) error {
|
func (s *BlobStore) call(ctx context.Context, serviceMethod string, args any, reply any) error {
|
||||||
err := s.withClient(ctx, func(ctx context.Context, client *rpc.Client) error {
|
err := s.withClient(ctx, func(ctx context.Context, client *rpc.Client) error {
|
||||||
if err := client.Call(ctx, serviceMethod, args, reply); err != nil {
|
if err := client.Call(ctx, serviceMethod, args, reply); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(remapBlobError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -96,7 +96,7 @@ func (s *DocumentStore) Upsert(ctx context.Context, collection string, doc stora
|
|||||||
func (s *DocumentStore) call(ctx context.Context, serviceMethod string, args any, reply any) error {
|
func (s *DocumentStore) call(ctx context.Context, serviceMethod string, args any, reply any) error {
|
||||||
err := s.withClient(ctx, func(ctx context.Context, client *rpc.Client) error {
|
err := s.withClient(ctx, func(ctx context.Context, client *rpc.Client) error {
|
||||||
if err := client.Call(ctx, serviceMethod, args, reply); err != nil {
|
if err := client.Call(ctx, serviceMethod, args, reply); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(remapDocumentError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,10 +1,31 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||||
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func remapBlobError(err error) error {
|
||||||
|
switch errors.Cause(err).Error() {
|
||||||
|
case storage.ErrBlobNotFound.Error():
|
||||||
|
return storage.ErrBlobNotFound
|
||||||
|
case storage.ErrBucketClosed.Error():
|
||||||
|
return storage.ErrBucketClosed
|
||||||
|
default:
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func remapDocumentError(err error) error {
|
||||||
|
switch errors.Cause(err).Error() {
|
||||||
|
case storage.ErrDocumentNotFound.Error():
|
||||||
|
return storage.ErrDocumentNotFound
|
||||||
|
default:
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func remapShareError(err error) error {
|
func remapShareError(err error) error {
|
||||||
switch errors.Cause(err).Error() {
|
switch errors.Cause(err).Error() {
|
||||||
case share.ErrAttributeRequired.Error():
|
case share.ErrAttributeRequired.Error():
|
||||||
|
Reference in New Issue
Block a user