func FromRPCError()

in spark/sparkerrors/errors.go [139:173]


func FromRPCError(e error) *SparkError {
	status := status.Convert(e)
	// If there was no error, simply pass through.
	if status == nil {
		return nil
	}
	result := &SparkError{
		Message: status.Message(),
		Code:    status.Code(),
		status:  status,
	}

	// Now lets, check if we can extract the error info from the details.
	for _, d := range status.Details() {
		switch info := d.(type) {
		case *errdetails.ErrorInfo:
			// Parse the parameters from the error details, but only parse them if
			// they're present.
			var params map[string]string
			if v, ok := info.GetMetadata()["messageParameters"]; ok {
				err := json.Unmarshal([]byte(v), &params)
				if err == nil {
					// The message parameters is properly formatted JSON, if for some reason
					// this is not the case, errors are ignored.
					result.Parameters = params
				}
			}
			result.SqlState = info.GetMetadata()["sqlState"]
			result.ErrorClass = info.GetMetadata()["errorClass"]
			result.ErrorId = info.GetMetadata()["errorId"]
			result.Reason = info.Reason
		}
	}
	return result
}