Ejemplo n.º 1
0
/*
 * Write the exception to the protocol.
 *
 * Does not assume the protocol's transport is ready for writing (you must prepare this yourself.)
 * Begins writing, writes the exception, and flushes the protocol's transport.
 */
func TWriteException(name string, seqId int32, prot thrift.TProtocol, exc thrift.TException) {
	// see whihch of the known thrift exception types it was
	_, isProtExc := exc.(thrift.TProtocolException)
	appExc, isAppExc := exc.(thrift.TApplicationException)
	_, isTransExc := exc.(thrift.TTransportException)

	// write the exception header
	prot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)

	// convert it into an application exception if not already
	if !isAppExc {
		if isProtExc {
			appExc = thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, exc.Error())
		} else if isTransExc {
			appExc = thrift.NewTApplicationException(thrift.INTERNAL_ERROR, exc.Error())
		} else {
			appExc = thrift.NewTApplicationExceptionMessage(exc.Error())
		}
	}

	appExc.Write(prot)

	// finish it
	prot.WriteMessageEnd()
	prot.Transport().Flush()
}
Ejemplo n.º 2
0
func (ce *CassandraCommand) writeArgsMessage(oprot thrift.TProtocol) thrift.TException {
	success, texec, err := ce.argsProc.WriteArgs(oprot)
	if success {
		return nil
	}
	if texec != nil {
		return texec
	}
	return thrift.NewTApplicationExceptionMessage(fmt.Sprintf("%s", err))
}