vesoft-inc/nebula-go

Compile a list of error handling in go client

wenhaocs opened this issue · 2 comments

Compile a list of error handling in go client
Aiee commented

Nebula GO Error Code Gudie

ResultSet is a wrapper of ExecutionResponse, and ExecutionResponse contains the error code returned from the Nebula service.

type ResultSet struct {
	resp            *graph.ExecutionResponse
	columnNames     []string
	colNameIndexMap map[string]int
	timezoneInfo    timezoneInfo
}

type ExecutionResponse struct {
  ErrorCode nebula0.ErrorCode
  LatencyInUs int64
  Data *nebula0.DataSet 
  SpaceName []byte 
  ErrorMsg []byte 
  PlanDesc *PlanDescription 
  Comment []byte 
}

In most cases, an error code will be returned with an error message to the user.

// Execute a query and handle the error
resultSet, err := session.Execute(createSchema)
if err != nil {
    fmt.Print(err.Error())
    return
}

some common error codes from the Nebula service:

  1. ErrorCode_SUCCEEDED
    • The query is executed successfully
  2. ErrorCode_E_BAD_USERNAME_PASSWORD
    • check user credentials
  3. ErrorCode_E_SESSION_INVALID
    • session expired, get a new session
  4. ErrorCode_E_SESSION_TIMEOUT
    • session is timeout, get a new session
  5. ErrorCode_E_SYNTAX_ERROR
    • syntax error in the query, check the query
  6. ErrorCode_E_EXECUTION_ERROR
    • runtime error occurs when executing the query, check the error message for details
  7. ErrorCode_E_USER_NOT_FOUND
    • the user does not exist
  8. ErrorCode_E_BAD_PERMISSION
    • current user has no permission to execute the query(i.g. KILL SESSIONS)
  9. ErrorCode_E_SEMANTIC_ERROR
    • semantic error in the query, check the query
  10. ErrorCode_E_LEADER_CHANGE
    • retry

If one graphd instance is down due to maintenance or unexpected error, refer to the following logic to retry and reconnect to other graphd. https://github.com/vesoft-inc/nebula-go/blob/master/session.go#L39-L45

        err2, ok := err.(thrift.TransportException)
	if !ok {
		return err
	}
	if err2.TypeID() != thrift.END_OF_FILE {
		return err
	}