hyperjumptech/grule-rule-engine

Error Tracing

sunilgandipadala opened this issue · 0 comments

Describe the bug
When I am working with a customer method that is related to Grule. Due to some reasons, its getting panic errors, like below
error while executing rule rule_490c528e12bc4c659e0f46dc8ee74a95. got rule engine execute panic ! recovered : runtime error: invalid memory address or nil pointer dereference

Now, I want to find the line, which causing this error in my code. Is there any thing in Grule, that it will help me to resolve.

To Reproduce
Steps to reproduce the behavior:

  1. I create code for this and that
    `
    func (r *ApiExecutor) Setup(props map[string]any) error { //grule method
    if r.WorkflowNode.Type == NODE_TYPE_APPEND {
    if entry, ok := props[PROP_KEY_API_CONNECTION]; ok {
    dataConnection, err := service.FetchActiveDataConnectionById(shared.PtrInt64From(shared.ConvertToInt64(entry)))
    if err != nil {
    logger.Error().Msgf("Error while fetching data Connection for append Node for workflow Id :: %v :: %v", r.WorkflowNode.ID, err)
    return shared.NewError(err.DebugInfo)
    }

     	//if dataConnection == nil || dataConnection.ConnectionDetailStruct == nil || dataConnection.ConnectionDetailStruct.ApiConnection == nil {
     	logger.Error().Msgf("ApiExecutor() :: Setup :: apiConnection is nil for dataConnection :: %+v", errors.NewKind("Api Connection is nil").New())
     	//	return shared.NewError("apiConnection is nil for dataConnection")
     	//}
    
     	if entry, ok := props[PROP_KEY_CONTEXT_KEY_MAPPING]; ok {
     		shared.ConvertInterfaceToTargetType(entry, &nodeParameters)
     		for _, item := range nodeParameters {
     			contextKeyMap[item.WorkflowKey] = item.Context
     			if item.Context == service.CONTEXT_WORKFLOW {
     				contextKeyMap[item.WorkflowKey] += service.CONTEXT_WORKFLOW_SEPERATOR + item.NodeId
     			}
     		}
     	}
     	errorMsg := someFunction()
     	if errorMsg != nil {
     		log.Info().Msgf("Error: %v", err)
     	}
    
     	service.MapDestinationAndSourceKeyValues(dataConnection.ConnectionDetailStruct.ApiConnection.QueryParameters, contextKeyMap, r.DataContext, "")
     	logger.Info().Msgf("ApiExecutor() :: QueryParameters prepared for the dataConnectionId :: %v :: %v", dataConnection.Id, dataConnection.ConnectionDetailStruct.ApiConnection.QueryParameters)
     	service.PreparePayloadByType(dataConnection.ConnectionDetailStruct.ApiConnection.RequestBody, shared.PtrStringToString(dataConnection.ConnectionDetailStruct.ApiConnection.Method), contextKeyMap, r.DataContext, "")
     	logger.Info().Msgf("ApiExecutor() :: RequestBody prepared for the dataConnectionId :: %v :: %v", dataConnection.Id, dataConnection.ConnectionDetailStruct.ApiConnection.RequestBody)
     	r.connector = &service.ApiConnector{IApiConnector: dataConnection.ConnectionDetailStruct.ApiConnection}
     }
    

    }
    return nil
    }

`

There where I have commented the lines, then I am getting the above error, if I uncomment them it's working fine.
4. Instead of that panic thing, can I able to get that thing as an error message(log).