Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2854

Go Struct writer and reader looses important error information

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.2
    • 0.9.3
    • Go - Compiler
    • None

    Description

      The GO Compiler generates code for a struct so that the following occurs:

      When an error occurs while reading or writing, a new error is created with additional text information using

      fmt.Errorf

      .
      By doing this the original error is completely lost. This is a real problem because errors of type TTransportException and TProtocolExceptions which contain additional information are lost. This will cause bad error handling, as the server implementation is dependent on those information.

      In my personal fork, I have a quick'n dirty fix for this, but I'm looking for a better option.

      Maybe instead of

      fmt.Errorf

      we could use this:

      // Prepends additional information to an error without losing the Thrift interface
      func PrependError(err error, prepend string) error {
        if t, ok := err.(TTransportException); ok {
          return NewTTransportException(t.TypeId(), prepend+t.Error())
        }
        if t, ok := err.(TProtocolException); ok {
          return NewTProtocolExceptionWithType(t.TypeId(), errors.New(prepend+err.Error()))
        }
        if t, ok := err.(TApplicationException); ok {
          return NewTApplicationException(t.TypeId(), prepend+t.Error())
        }
      
        return errors.New(prepend + err.Error())
      }
      

      I want to discuss this first here, because making a patch is quiet some work and I don't want major changes after I create a fix.

      Attachments

        Activity

          People

            jensg Jens Geyer
            cvlchinet Chi Vinh Le
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: