What are the pros and cons of using a string and using int to describe an
error?
in net/http:
37 // HTTP request parsing errors. 38 type ProtocolError struct { 39 ErrorString string 40 } 41 42 func (err *ProtocolError) Error() string { return err.ErrorString } 43 44 var ( 45 ErrHeaderTooLong = &ProtocolError{"header too long"} 46 ErrShortBody = &ProtocolError{"entity body too short"} 47 ErrNotSupported = &ProtocolError{"feature not supported"} 48 ErrUnexpectedTrailer = &ProtocolError{"trailer header without chunked transfer encoding"} 49 ErrMissingContentLength = &ProtocolError{"missing ContentLength in HEAD response"} 50 ErrNotMultipart = &ProtocolError{"request Content-Type isn't multipart/form-data"} 51 ErrMissingBoundary = &ProtocolError{"no multipart boundary param in Content-Type"} 52 ) 53 54 type badStringError struct { 55 what string 56 str string 57 } 58 59 func (e *badStringError) Error() string { return fmt.Sprintf("%s %q", e.what, e.str) } 60
in crypto/x509:
15 type InvalidReason int
const ([...] 30 TooManyIntermediates 31 // IncompatibleUsage results when the certificate's key usage indicates 32 // that it may only be used for a different purpose. 33 IncompatibleUsage 34 ) 35 36 // CertificateInvalidError results when an odd error occurs. Users of this 37 // library probably want to handle all these errors uniformly. 38 type CertificateInvalidError struct { 39 Cert *Certificate 40 Reason InvalidReason 41 } 42 43 func (e CertificateInvalidError) Error() string { 44 switch e.Reason {[...] 51 case TooManyIntermediates: 52 return "x509: too many intermediates for path length constraint" 53 case IncompatibleUsage: 54 return "x509: certificate specifies an incompatible key usage" 55 } 56 return "x509: unknown error" 57 } 58
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.