Procházet zdrojové kódy

feat: support detailed error messages

Yeuoly před 8 měsíci
rodič
revize
670096c977

+ 1 - 0
cmd/commandline/init/init.go

@@ -64,6 +64,7 @@ func initialize() model {
 	m.subMenuSeq = []subMenuKey{
 		SUB_MENU_KEY_PROFILE,
 		SUB_MENU_KEY_LANGUAGE,
+		SUB_MENU_KEY_CATEGORY,
 		SUB_MENU_KEY_PERMISSION,
 	}
 

+ 6 - 5
internal/cluster/plugin.go

@@ -241,14 +241,15 @@ func (c *Cluster) autoGCPlugins() error {
 	)
 }
 
-func (c *Cluster) IsPluginOnCurrentNode(identity plugin_entities.PluginUniqueIdentifier) bool {
+func (c *Cluster) IsPluginOnCurrentNode(identity plugin_entities.PluginUniqueIdentifier) (bool, error) {
 	_, ok := c.plugins.Load(identity.String())
 	if !ok {
-		if c.manager.Get(identity) == nil {
-			return false
+		_, err := c.manager.Get(identity)
+		if err != nil {
+			return false, err
 		} else {
-			return true
+			return true, nil
 		}
 	}
-	return ok
+	return ok, nil
 }

+ 4 - 4
internal/core/plugin_manager/manager.go

@@ -95,18 +95,18 @@ func Manager() *PluginManager {
 
 func (p *PluginManager) Get(
 	identity plugin_entities.PluginUniqueIdentifier,
-) plugin_entities.PluginLifetime {
+) (plugin_entities.PluginLifetime, error) {
 	if v, ok := p.m.Load(identity.String()); ok {
-		return v
+		return v, nil
 	}
 
 	// check if plugin is a serverless runtime
 	plugin_session_interface, err := p.getServerlessPluginRuntime(identity)
 	if err != nil {
-		return nil
+		return nil, err
 	}
 
-	return plugin_session_interface
+	return plugin_session_interface, nil
 }
 
 func (p *PluginManager) GetAsset(id string) ([]byte, error) {

+ 2 - 2
internal/server/endpoint.go

@@ -63,8 +63,8 @@ func (app *App) EndpointHandler(ctx *gin.Context, hook_id string, path string) {
 	}
 
 	// check if plugin exists in current node
-	if !app.cluster.IsPluginOnCurrentNode(plugin_unique_identifier) {
-		app.redirectPluginInvokeByPluginIdentifier(ctx, plugin_unique_identifier)
+	if ok, original_error := app.cluster.IsPluginOnCurrentNode(plugin_unique_identifier); !ok {
+		app.redirectPluginInvokeByPluginIdentifier(ctx, plugin_unique_identifier, original_error)
 	} else {
 		service.Endpoint(ctx, &endpoint, &plugin_installation, path)
 	}

+ 11 - 6
internal/server/middleware.go

@@ -78,10 +78,8 @@ func (app *App) RedirectPluginInvoke() gin.HandlerFunc {
 		}
 
 		// check if plugin in current node
-		if !app.cluster.IsPluginOnCurrentNode(
-			identity,
-		) {
-			app.redirectPluginInvokeByPluginIdentifier(ctx, identity)
+		if ok, original_error := app.cluster.IsPluginOnCurrentNode(identity); !ok {
+			app.redirectPluginInvokeByPluginIdentifier(ctx, identity, original_error)
 			ctx.Abort()
 		} else {
 			ctx.Next()
@@ -92,14 +90,21 @@ func (app *App) RedirectPluginInvoke() gin.HandlerFunc {
 func (app *App) redirectPluginInvokeByPluginIdentifier(
 	ctx *gin.Context,
 	plugin_unique_identifier plugin_entities.PluginUniqueIdentifier,
+	original_error error,
 ) {
 	// try find the correct node
 	nodes, err := app.cluster.FetchPluginAvailableNodesById(plugin_unique_identifier.String())
 	if err != nil {
-		ctx.AbortWithStatusJSON(500, gin.H{"error": "Internal server error"})
+		ctx.AbortWithStatusJSON(
+			500,
+			gin.H{"error": "Internal server error, " + original_error.Error() + ", " + err.Error()},
+		)
 		return
 	} else if len(nodes) == 0 {
-		ctx.AbortWithStatusJSON(404, gin.H{"error": "No available node"})
+		ctx.AbortWithStatusJSON(
+			404,
+			gin.H{"error": "No available node, " + original_error.Error()},
+		)
 		return
 	}
 

+ 2 - 2
internal/service/endpoint.go

@@ -54,8 +54,8 @@ func Endpoint(
 
 	// fetch plugin
 	manager := plugin_manager.Manager()
-	runtime := manager.Get(identifier)
-	if runtime == nil {
+	runtime, err := manager.Get(identifier)
+	if err != nil {
 		ctx.JSON(404, gin.H{"error": "plugin not found"})
 		return
 	}

+ 2 - 2
internal/service/session.go

@@ -22,8 +22,8 @@ func createSession[T any](
 
 	// try fetch plugin identifier from plugin id
 
-	runtime := manager.Get(r.UniqueIdentifier)
-	if runtime == nil {
+	runtime, err := manager.Get(r.UniqueIdentifier)
+	if err != nil {
 		return nil, errors.New("failed to get plugin runtime")
 	}