Repository: jhillyerd/enmime
Pull request #177 (2020-11-21 21:26:59)

Fix capitalized error strings
This is in preparation for introducing more thorough static checks on PRs.


Patch:
diff --git a/envelope.go b/envelope.go
index 11be3ce..dc3d97d 100644
--- a/envelope.go
+++ b/envelope.go
@@ -67,7 +67,7 @@ func (e *Envelope) GetHeaderValues(name string) []string {
 // If the header exists already, all existing values are replaced.
 func (e *Envelope) SetHeader(name string, value []string) error {
 	if name == "" {
-		return fmt.Errorf("Provide non-empty header name")
+		return fmt.Errorf("provide non-empty header name")
 	}
 
 	for i, v := range value {
@@ -84,7 +84,7 @@ func (e *Envelope) SetHeader(name string, value []string) error {
 // If the header does not exist already, it will be created.
 func (e *Envelope) AddHeader(name string, value string) error {
 	if name == "" {
-		return fmt.Errorf("Provide non-empty header name")
+		return fmt.Errorf("provide non-empty header name")
 	}
 
 	e.header.Add(name, mime.BEncoding.Encode("utf-8", value))
@@ -94,7 +94,7 @@ func (e *Envelope) AddHeader(name string, value string) error {
 // DeleteHeader deletes given header.
 func (e *Envelope) DeleteHeader(name string) error {
 	if name == "" {
-		return fmt.Errorf("Provide non-empty header name")
+		return fmt.Errorf("provide non-empty header name")
 	}
 
 	e.header.Del(name)
@@ -104,7 +104,7 @@ func (e *Envelope) DeleteHeader(name string) error {
 // AddressList returns a mail.Address slice with RFC 2047 encoded names converted to UTF-8
 func (e *Envelope) AddressList(key string) ([]*mail.Address, error) {
 	if e.header == nil {
-		return nil, fmt.Errorf("No headers available")
+		return nil, fmt.Errorf("no headers available")
 	}
 	if !AddressHeaders[strings.ToLower(key)] {
 		return nil, fmt.Errorf("%s is not an address header", key)
@@ -268,14 +268,14 @@ func parseMultiPartBody(root *Part, e *Envelope) error {
 	ctype := root.Header.Get(hnContentType)
 	mediatype, params, _, err := ParseMediaType(ctype)
 	if err != nil {
-		return fmt.Errorf("Unable to parse media type: %v", err)
+		return fmt.Errorf("unable to parse media type: %v", err)
 	}
 	if !strings.HasPrefix(mediatype, ctMultipartPrefix) {
-		return fmt.Errorf("Unknown mediatype: %v", mediatype)
+		return fmt.Errorf("unknown mediatype: %v", mediatype)
 	}
 	boundary := params[hpBoundary]
 	if boundary == "" {
-		return fmt.Errorf("Unable to locate boundary param in Content-Type header")
+		return fmt.Errorf("unable to locate boundary param in Content-Type header")
 	}
 
 	// Locate text body
diff --git a/internal/coding/base64.go b/internal/coding/base64.go
index 4edba5d..10b829f 100644
--- a/internal/coding/base64.go
+++ b/internal/coding/base64.go
@@ -54,7 +54,7 @@ func (bc *Base64Cleaner) Read(p []byte) (n int, err error) {
 			// Strip these silently: tab, \n, \r, space, equals sign.
 		case -1:
 			// Strip these, but warn the client.
-			bc.Errors = append(bc.Errors, fmt.Errorf("Unexpected %q in Base64 stream", buf[i]))
+			bc.Errors = append(bc.Errors, fmt.Errorf("unexpected %q in base64 stream", buf[i]))
 		default:
 			p[n] = buf[i]
 			n++
diff --git a/internal/coding/charsets.go b/internal/coding/charsets.go
index ab170ea..7d635d8 100644
--- a/internal/coding/charsets.go
+++ b/internal/coding/charsets.go
@@ -275,7 +275,7 @@ func init() {
 func ConvertToUTF8String(charset string, textBytes []byte) (string, error) {
 	csentry, ok := encodings[strings.ToLower(charset)]
 	if !ok {
-		return "", fmt.Errorf("Unsupported charset %q", charset)
+		return "", fmt.Errorf("unsupported charset %q", charset)
 	}
 	input := bytes.NewReader(textBytes)
 	reader := transform.NewReader(input, csentry.e.NewDecoder())
@@ -296,7 +296,7 @@ func NewCharsetReader(charset string, input io.Reader) (io.Reader, error) {
 	}
 	csentry, ok := encodings[strings.ToLower(charset)]
 	if !ok {
-		return nil, fmt.Errorf("Unsupported charset %q", charset)
+		return nil, fmt.Errorf("unsupported charset %q", charset)
 	}
 	return transform.NewReader(input, csentry.e.NewDecoder()), nil
 }


Test patch:
diff --git a/envelope_test.go b/envelope_test.go
index 600f8ee..f71ca44 100644
--- a/envelope_test.go
+++ b/envelope_test.go
@@ -1137,7 +1137,7 @@ func TestNilHeaderValues(t *testing.T) {
 func TestSetHeaderEmptyName(t *testing.T) {
 	e := &enmime.Envelope{}
 	err := e.SetHeader("", nil)
-	if err == nil || err.Error() != "Provide non-empty header name" {
+	if err == nil || err.Error() != "provide non-empty header name" {
 		t.Fatal("Cannot set a header without a name, failed")
 	}
 }
@@ -1145,7 +1145,7 @@ func TestSetHeaderEmptyName(t *testing.T) {
 func TestAddHeaderEmptyName(t *testing.T) {
 	e := &enmime.Envelope{}
 	err := e.AddHeader("", "")
-	if err == nil || err.Error() != "Provide non-empty header name" {
+	if err == nil || err.Error() != "provide non-empty header name" {
 		t.Fatal("Cannot add a header without a name, failed")
 	}
 }
@@ -1153,7 +1153,7 @@ func TestAddHeaderEmptyName(t *testing.T) {
 func TestDeleteHeaderEmptyName(t *testing.T) {
 	e := &enmime.Envelope{}
 	err := e.DeleteHeader("")
-	if err == nil || err.Error() != "Provide non-empty header name" {
+	if err == nil || err.Error() != "provide non-empty header name" {
 		t.Fatal("Cannot add a header without a name, failed")
 	}
 }