<commit_before>package app

import (
	"fmt"
	"net/http"
	"reflect"
	"syscall"
)

// Error represents an error which, besides a message,
// has also an assocciated status code to be sent to
// the client.
type Error interface {
	error
	StatusCode() int
}

// Indicates that something wasn't found. Its status code
// is 404.
type NotFoundError struct {
	Kind string
}

func (n *NotFoundError) StatusCode() int {
	return http.StatusNotFound
}

func (n *NotFoundError) Error() string {
	if n.Kind != "" {
		fmt.Sprintf("%s not found", n.Kind)
	}
	return "Not found"
}

// Indicates that a required parameter is mising. Its
// status code is 400.
type MissingParameterError struct {
	Name string
}

func (m *MissingParameterError) StatusCode() int {
	return http.StatusBadRequest
}

func (m *MissingParameterError) Error() string {
	return fmt.Sprintf("Missing required parameter \"%s\"", m.Name)
}

// Indicates that a parameter does not have the required type
// (e.g. an int was requested but a string was provided). Its
// status code is 400.
type InvalidParameterTypeError struct {
	*MissingParameterError
	Type reflect.Type
}

func (i *InvalidParameterTypeError) Error() string {
	return fmt.Sprintf("Required parameter %q must be of type %v", i.Name, i.Type)
}

// NotFound panics with NotFoundError.
func NotFound() {
	KindNotFound("")
}

// KindNotFound panics with a NotFoundError indicating
// what was not found (.e.g "Article not found).
func KindNotFound(kind string) {
	panic(&NotFoundError{kind})
}

// MissingParameter panics with a MissingParameterError, using
// the given parameter name.
func MissingParameter(name string) {
	panic(&MissingParameterError{name})
}

// InvalidParameterType panics with an InvalidParameterTypeError
// using the given parameter name and type.
func InvalidParameterType(name string, typ reflect.Type) {
	panic(&InvalidParameterTypeError{&MissingParameterError{name}, typ})
}

func isIgnorable(err interface{}) bool {
	if e, ok := err.(error); ok && e == syscall.EPIPE {
		// Client closed the connection
		return true
	}
	return false
}<commit_msg>Detect EPIPE better<commit_after>package app

import (
	"fmt"
	"net"
	"net/http"
	"reflect"
	"syscall"
)

// Error represents an error which, besides a message,
// has also an assocciated status code to be sent to
// the client.
type Error interface {
	error
	StatusCode() int
}

// Indicates that something wasn't found. Its status code
// is 404.
type NotFoundError struct {
	Kind string
}

func (n *NotFoundError) StatusCode() int {
	return http.StatusNotFound
}

func (n *NotFoundError) Error() string {
	if n.Kind != "" {
		fmt.Sprintf("%s not found", n.Kind)
	}
	return "Not found"
}

// Indicates that a required parameter is mising. Its
// status code is 400.
type MissingParameterError struct {
	Name string
}

func (m *MissingParameterError) StatusCode() int {
	return http.StatusBadRequest
}

func (m *MissingParameterError) Error() string {
	return fmt.Sprintf("Missing required parameter \"%s\"", m.Name)
}

// Indicates that a parameter does not have the required type
// (e.g. an int was requested but a string was provided). Its
// status code is 400.
type InvalidParameterTypeError struct {
	*MissingParameterError
	Type reflect.Type
}

func (i *InvalidParameterTypeError) Error() string {
	return fmt.Sprintf("Required parameter %q must be of type %v", i.Name, i.Type)
}

// NotFound panics with NotFoundError.
func NotFound() {
	KindNotFound("")
}

// KindNotFound panics with a NotFoundError indicating
// what was not found (.e.g "Article not found).
func KindNotFound(kind string) {
	panic(&NotFoundError{kind})
}

// MissingParameter panics with a MissingParameterError, using
// the given parameter name.
func MissingParameter(name string) {
	panic(&MissingParameterError{name})
}

// InvalidParameterType panics with an InvalidParameterTypeError
// using the given parameter name and type.
func InvalidParameterType(name string, typ reflect.Type) {
	panic(&InvalidParameterTypeError{&MissingParameterError{name}, typ})
}

func isIgnorable(err interface{}) bool {
	if e, ok := err.(error); ok {
		if ne, ok := e.(*net.OpError); ok {
			e = ne.Err
		}
		if e == syscall.EPIPE {
			// Client closed the connection
			return true
		}
	}
	return false
}
{'fraction_non_alphanumeric': 0.10850714787907195, 'fraction_numerical': 0.004218420435903445, 'mean_word_length': 4.154589371980676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3544807', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1268, 'n_words': 467}