Exemple #1
0
func handleError(err error, tiServer string) errors.Error {

	if strings.Contains(strings.ToLower(err.Error()), "connection refused") {
		return errors.NewShellErrorCannotConnect("Unable to connect to query service " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "unsupported protocol") {
		return errors.NewShellErrorUnsupportedProtocol("Unsupported Protocol Scheme " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "no such host") {
		return errors.NewShellErrorNoSuchHost("No such Host " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "unknown port tcp") {
		return errors.NewShellErrorUnknownPorttcp("Unknown port " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "no host in request url") {
		return errors.NewShellErrorNoHostInRequestUrl("No Host in request URL " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "no route to host") {
		return errors.NewShellErrorNoRouteToHost("No Route to host " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "operation timed out") {
		return errors.NewShellErrorOperationTimeout("Operation timed out. Check query service url " + tiServer)
	} else if strings.Contains(strings.ToLower(err.Error()), "network is unreachable") {
		return errors.NewShellErrorUnreachableNetwork("Network is unreachable " + tiServer)
	} else {
		return errors.NewError(err, "")
	}
}
Exemple #2
0
func HandleError(err int, msg string) errors.Error {

	switch err {

	//Connection errors
	case errors.CONNECTION_REFUSED:
		return errors.NewShellErrorCannotConnect("Unable to connect to query service " + SERVICE_URL)
	case errors.UNSUPPORTED_PROTOCOL:
		return errors.NewShellErrorUnsupportedProtocol("Unsupported Protocol Scheme " + SERVICE_URL)
	case errors.NO_SUCH_HOST:
		return errors.NewShellErrorNoSuchHost("No such Host " + SERVICE_URL)
	case errors.NO_HOST_IN_URL:
		return errors.NewShellErrorNoHostInRequestUrl("No Host in request URL " + SERVICE_URL)
	case errors.UNKNOWN_PORT_TCP:
		return errors.NewShellErrorUnknownPorttcp("Unknown port " + SERVICE_URL)
	case errors.NO_ROUTE_TO_HOST:
		return errors.NewShellErrorNoRouteToHost("No Route to host " + SERVICE_URL)
	case errors.UNREACHABLE_NETWORK:
		return errors.NewShellErrorUnreachableNetwork("Network is unreachable ")
	case errors.NO_CONNECTION:
		return errors.NewShellErrorNoConnection("Not Connected to any instance. Use \\CONNECT command. ")
	case errors.GO_N1QL_OPEN:
		return errors.NewShellErrorGon1qlOpen(msg)

	//Read/Write/Update file errors
	case errors.READ_FILE:
		return errors.NewShellErrorReadFile("Error during file read. ")
	case errors.WRITE_FILE:
		return errors.NewShellErrorWriteFile("Error during file write. ")
	case errors.FILE_OPEN:
		return errors.NewShellErrorOpenFile("Unable to open file. ")
	case errors.FILE_CLOSE:
		return errors.NewShellErrorCloseFile("Unable to close file. ")

	//Authentication Errors.
	case errors.INVALID_PASSWORD:
		return errors.NewShellErrorInvalidPassword(msg)
	case errors.INVALID_USERNAME:
		return errors.NewShellErrorInvalidUsername(msg)
	case errors.MISSING_CREDENTIAL:
		return errors.NewShellErrorMissingCredential("Username or Password missing in -credentials/-c option.")

	//Command Errors
	case errors.NO_SUCH_COMMAND:
		return errors.NewShellErrorNoSuchCommand("Command does not exist.")
	case errors.NO_SUCH_PARAM:
		return errors.NewShellErrorNoSuchParam("Parameter does not exist : " + msg)
	case errors.TOO_MANY_ARGS:
		return errors.NewShellErrorTooManyArgs("Too many input arguments to command.")
	case errors.TOO_FEW_ARGS:
		return errors.NewShellErrorTooFewArgs("Too few input arguments to command.")
	case errors.STACK_EMPTY:
		return errors.NewShellErrorStackEmpty("Stack Empty.")
	case errors.NO_SUCH_ALIAS:
		return errors.NewShellErrorNoSuchAlias("Alias does not exist")

	//Generic Errors
	case errors.OPERATION_TIMEOUT:
		return errors.NewShellErrorOperationTimeout("Operation timed out. Check query service url " + SERVICE_URL)
	case errors.ROWS_SCAN:
		return errors.NewShellErrorRowsScan(msg)
	case errors.JSON_MARSHAL:
		return errors.NewShellErrorJsonMarshal(msg)
	case errors.JSON_UNMARSHAL:
		return errors.NewShellErrorJsonUnmarshal(msg)
	case errors.GON1QL_QUERY:
		return errors.NewShellErrorGon1qlQueryMethod(msg)
	case errors.WRITER_OUTPUT:
		return errors.NewShellErrorWriterOutput("Error with io Writer. ")
	case errors.UNBALANCED_PAREN:
		return errors.NewShellErrorUnbalancedParen("Unbalanced Parenthesis in the input.")
	case errors.ROWS_CLOSE:
		return errors.NewShellErrorRowsClose(msg)

	default:
		return errors.NewShellErrorUnkownError(msg)
	}

}