chore: prepare docfill project for gitea
This commit is contained in:
74
internal/docfill/errors.go
Normal file
74
internal/docfill/errors.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package docfill
|
||||
|
||||
type ErrorCode string
|
||||
|
||||
const (
|
||||
CodeCLIUsage ErrorCode = "CLI_USAGE"
|
||||
CodeConfigRead ErrorCode = "CONFIG_READ"
|
||||
CodeConfigParse ErrorCode = "CONFIG_PARSE"
|
||||
CodeConfigValidate ErrorCode = "CONFIG_VALIDATE"
|
||||
CodeDataExcel ErrorCode = "DATA_EXCEL"
|
||||
CodeDataSQLite ErrorCode = "DATA_SQLITE"
|
||||
CodeDataEmpty ErrorCode = "DATA_EMPTY"
|
||||
CodeDataFilterField ErrorCode = "DATA_FILTER_FIELD"
|
||||
CodeDataFilterValue ErrorCode = "DATA_FILTER_VALUE"
|
||||
CodeDataFilterNoMatch ErrorCode = "DATA_FILTER_NO_MATCH"
|
||||
CodeDataFilterMultiMatch ErrorCode = "DATA_FILTER_MULTI_MATCH"
|
||||
CodeTemplateOpen ErrorCode = "TEMPLATE_OPEN"
|
||||
CodeTemplateFieldMissing ErrorCode = "TEMPLATE_FIELD_MISSING"
|
||||
CodeTemplateUnresolved ErrorCode = "TEMPLATE_UNRESOLVED"
|
||||
CodeOutputExists ErrorCode = "OUTPUT_EXISTS"
|
||||
CodeOutputWrite ErrorCode = "OUTPUT_WRITE"
|
||||
CodeInternal ErrorCode = "INTERNAL"
|
||||
)
|
||||
|
||||
type AppError struct {
|
||||
Code ErrorCode
|
||||
Message string
|
||||
Hint string
|
||||
Context map[string]string
|
||||
Cause error
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string {
|
||||
if e == nil {
|
||||
return ""
|
||||
}
|
||||
if e.Cause == nil {
|
||||
return e.Message
|
||||
}
|
||||
return e.Message + ": " + e.Cause.Error()
|
||||
}
|
||||
|
||||
func (e *AppError) Unwrap() error {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
return e.Cause
|
||||
}
|
||||
|
||||
func appError(code ErrorCode, message string) *AppError {
|
||||
return &AppError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Context: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *AppError) withHint(hint string) *AppError {
|
||||
e.Hint = hint
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *AppError) withCause(cause error) *AppError {
|
||||
e.Cause = cause
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *AppError) withContext(key, value string) *AppError {
|
||||
if e.Context == nil {
|
||||
e.Context = make(map[string]string)
|
||||
}
|
||||
e.Context[key] = value
|
||||
return e
|
||||
}
|
||||
Reference in New Issue
Block a user