summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-08-31 12:34:38 +0800
committerLoyalsoldier <[email protected]>2024-08-31 12:34:38 +0800
commit1e4cb746b9ca67b9d9dabdc65f42f495eb4cfbcd (patch)
treeee3de1a60416c7f56dcc99a2cf7715b9b8f4e5a2
parentdeff06ac0f59751bb9857bc7d645b756b6133ddf (diff)
Chore: make error messages consistent across formats
-rw-r--r--plugin/maxmind/asn_csv.go4
-rw-r--r--plugin/maxmind/country_csv.go10
-rw-r--r--plugin/maxmind/mmdb_in.go2
-rw-r--r--plugin/maxmind/mmdb_out.go2
-rw-r--r--plugin/mihomo/mrs_in.go12
-rw-r--r--plugin/mihomo/mrs_out.go2
-rw-r--r--plugin/plaintext/common_in.go2
-rw-r--r--plugin/plaintext/text_in.go12
-rw-r--r--plugin/singbox/srs_in.go14
-rw-r--r--plugin/singbox/srs_out.go2
-rw-r--r--plugin/special/cutter.go4
-rw-r--r--plugin/special/lookup.go2
-rw-r--r--plugin/special/stdin.go2
-rw-r--r--plugin/v2ray/dat_in.go6
-rw-r--r--plugin/v2ray/dat_out.go2
15 files changed, 39 insertions, 39 deletions
diff --git a/plugin/maxmind/asn_csv.go b/plugin/maxmind/asn_csv.go
index e738a44b..8c90d60d 100644
--- a/plugin/maxmind/asn_csv.go
+++ b/plugin/maxmind/asn_csv.go
@@ -129,7 +129,7 @@ func (g *geoLite2ASNCSV) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeASNCSV, g.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", g.Type, g.Action)
}
var ignoreIPType lib.IgnoreIPOption
@@ -190,7 +190,7 @@ func (g *geoLite2ASNCSV) process(file string, entries map[string]*lib.Entry) err
}
if len(record) < 2 {
- return fmt.Errorf("❌ [type %s | action %s] invalid record: %v", typeASNCSV, g.Action, record)
+ return fmt.Errorf("❌ [type %s | action %s] invalid record: %v", g.Type, g.Action, record)
}
if listArr, found := g.Want[strings.TrimSpace(record[1])]; found {
diff --git a/plugin/maxmind/country_csv.go b/plugin/maxmind/country_csv.go
index 090de13a..eb538dec 100644
--- a/plugin/maxmind/country_csv.go
+++ b/plugin/maxmind/country_csv.go
@@ -123,7 +123,7 @@ func (g *geoLite2CountryCSV) Input(container lib.Container) (lib.Container, erro
}
if len(entries) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeCountryCSV, g.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", g.Type, g.Action)
}
var ignoreIPType lib.IgnoreIPOption
@@ -176,7 +176,7 @@ func (g *geoLite2CountryCSV) getCountryCode() (map[string]string, error) {
ccMap := make(map[string]string)
for _, line := range lines[1:] {
if len(line) < 5 {
- return nil, fmt.Errorf("❌ [type %s | action %s] invalid record: %v", typeCountryCSV, g.Action, line)
+ return nil, fmt.Errorf("❌ [type %s | action %s] invalid record: %v", g.Type, g.Action, line)
}
id := strings.TrimSpace(line[0])
@@ -193,7 +193,7 @@ func (g *geoLite2CountryCSV) getCountryCode() (map[string]string, error) {
}
if len(ccMap) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] invalid country code data", typeCountryCSV, g.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] invalid country code data", g.Type, g.Action)
}
return ccMap, nil
@@ -201,7 +201,7 @@ func (g *geoLite2CountryCSV) getCountryCode() (map[string]string, error) {
func (g *geoLite2CountryCSV) process(file string, ccMap map[string]string, entries map[string]*lib.Entry) error {
if len(ccMap) == 0 {
- return fmt.Errorf("❌ [type %s | action %s] invalid country code data", typeCountryCSV, g.Action)
+ return fmt.Errorf("❌ [type %s | action %s] invalid country code data", g.Type, g.Action)
}
if entries == nil {
entries = make(map[string]*lib.Entry, len(ccMap))
@@ -234,7 +234,7 @@ func (g *geoLite2CountryCSV) process(file string, ccMap map[string]string, entri
}
if len(record) < 4 {
- return fmt.Errorf("❌ [type %s | action %s] invalid record: %v", typeCountryCSV, g.Action, record)
+ return fmt.Errorf("❌ [type %s | action %s] invalid record: %v", g.Type, g.Action, record)
}
ccID := ""
diff --git a/plugin/maxmind/mmdb_in.go b/plugin/maxmind/mmdb_in.go
index 3ee1eacb..fc891c7a 100644
--- a/plugin/maxmind/mmdb_in.go
+++ b/plugin/maxmind/mmdb_in.go
@@ -105,7 +105,7 @@ func (m *maxmindMMDBIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeMaxmindMMDBIn, m.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", m.Type, m.Action)
}
var ignoreIPType lib.IgnoreIPOption
diff --git a/plugin/maxmind/mmdb_out.go b/plugin/maxmind/mmdb_out.go
index e42ea02d..964971d7 100644
--- a/plugin/maxmind/mmdb_out.go
+++ b/plugin/maxmind/mmdb_out.go
@@ -123,7 +123,7 @@ func (m *mmdbOut) Output(container lib.Container) error {
return err
}
} else {
- return fmt.Errorf("type %s | action %s failed to write file", m.Type, m.Action)
+ return fmt.Errorf("❌ [type %s | action %s] failed to write file", m.Type, m.Action)
}
return nil
diff --git a/plugin/mihomo/mrs_in.go b/plugin/mihomo/mrs_in.go
index 4976e071..a3ab9364 100644
--- a/plugin/mihomo/mrs_in.go
+++ b/plugin/mihomo/mrs_in.go
@@ -50,11 +50,11 @@ func newMRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
if tmp.Name == "" && tmp.URI == "" && tmp.InputDir == "" {
- return nil, fmt.Errorf("type %s | action %s missing inputdir or name or uri", typeMRSIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] missing inputDir or name or uri", typeMRSIn, action)
}
if (tmp.Name != "" && tmp.URI == "") || (tmp.Name == "" && tmp.URI != "") {
- return nil, fmt.Errorf("type %s | action %s name & uri must be specified together", typeMRSIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", typeMRSIn, action)
}
// Filter want list
@@ -115,7 +115,7 @@ func (m *mrsIn) Input(container lib.Container) (lib.Container, error) {
err = m.walkLocalFile(m.URI, m.Name, entries)
}
default:
- return nil, fmt.Errorf("config missing argument inputDir or name or uri")
+ return nil, fmt.Errorf("❌ [type %s | action %s] config missing argument inputDir or name or uri", m.Type, m.Action)
}
if err != nil {
@@ -181,7 +181,7 @@ func (m *mrsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
// check filename
if !regexp.MustCompile(`^[a-zA-Z0-9_.\-]+$`).MatchString(entryName) {
- return fmt.Errorf("filename %s cannot be entry name, please remove special characters in it", entryName)
+ return fmt.Errorf("❌ [type %s | action %s] filename %s cannot be entry name, please remove special characters in it", m.Type, m.Action, entryName)
}
// remove file extension but not hidden files of which filename starts with "."
@@ -193,7 +193,7 @@ func (m *mrsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
entryName = strings.ToUpper(entryName)
if _, found := entries[entryName]; found {
- return fmt.Errorf("found duplicated list %s", entryName)
+ return fmt.Errorf("❌ [type %s | action %s] found duplicated list %s", m.Type, m.Action, entryName)
}
file, err := os.Open(path)
@@ -217,7 +217,7 @@ func (m *mrsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
defer resp.Body.Close()
if resp.StatusCode != 200 {
- return fmt.Errorf("failed to get remote file %s, http status code %d", url, resp.StatusCode)
+ return fmt.Errorf("❌ [type %s | action %s] failed to get remote file %s, http status code %d", m.Type, m.Action, url, resp.StatusCode)
}
if err := m.generateEntries(name, resp.Body, entries); err != nil {
diff --git a/plugin/mihomo/mrs_out.go b/plugin/mihomo/mrs_out.go
index 14d48428..fe9480da 100644
--- a/plugin/mihomo/mrs_out.go
+++ b/plugin/mihomo/mrs_out.go
@@ -148,7 +148,7 @@ func (m *mrsOut) generate(entry *lib.Entry) error {
}
if len(ipRanges) == 0 {
- return fmt.Errorf("entry %s has no CIDR", entry.GetName())
+ return fmt.Errorf("❌ [type %s | action %s] entry %s has no CIDR", m.Type, m.Action, entry.GetName())
}
filename := strings.ToLower(entry.GetName()) + ".mrs"
diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go
index fbaf21ff..06032c9d 100644
--- a/plugin/plaintext/common_in.go
+++ b/plugin/plaintext/common_in.go
@@ -200,7 +200,7 @@ func (t *textIn) scanFileForJSONIn(reader io.Reader, entry *lib.Entry) error {
}
if !gjson.ValidBytes(data) {
- return fmt.Errorf("invalid JSON data")
+ return fmt.Errorf("❌ [type %s | action %s] invalid JSON data", t.Type, t.Action)
}
// JSON Path syntax:
diff --git a/plugin/plaintext/text_in.go b/plugin/plaintext/text_in.go
index 9bc0d73f..68d60eaa 100644
--- a/plugin/plaintext/text_in.go
+++ b/plugin/plaintext/text_in.go
@@ -55,7 +55,7 @@ func newTextIn(iType string, action lib.Action, data json.RawMessage) (lib.Input
}
if iType == typeJSONIn && len(tmp.JSONPath) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] missing jsonPath", typeJSONIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] missing jsonPath", iType, action)
}
if tmp.InputDir == "" {
@@ -131,7 +131,7 @@ func (t *textIn) Input(container lib.Container) (lib.Container, error) {
err = t.appendIPOrCIDR(t.IPOrCIDR, t.Name, entries)
default:
- return nil, fmt.Errorf("config missing argument inputDir or name or uri")
+ return nil, fmt.Errorf("❌ [type %s | action %s] config missing argument inputDir or name or uri or ipOrCIDR", t.Type, t.Action)
}
if err != nil {
@@ -147,7 +147,7 @@ func (t *textIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("type %s | action %s no entry is generated", t.Type, t.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", t.Type, t.Action)
}
for _, entry := range entries {
@@ -197,7 +197,7 @@ func (t *textIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
// check filename
if !regexp.MustCompile(`^[a-zA-Z0-9_.\-]+$`).MatchString(entryName) {
- return fmt.Errorf("filename %s cannot be entry name, please remove special characters in it", entryName)
+ return fmt.Errorf("❌ [type %s | action %s] filename %s cannot be entry name, please remove special characters in it", t.Type, t.Action, entryName)
}
// remove file extension but not hidden files of which filename starts with "."
@@ -213,7 +213,7 @@ func (t *textIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
return nil
}
if _, found := entries[entryName]; found {
- return fmt.Errorf("found duplicated list %s", entryName)
+ return fmt.Errorf("❌ [type %s | action %s] found duplicated list %s", t.Type, t.Action, entryName)
}
entry := lib.NewEntry(entryName)
@@ -239,7 +239,7 @@ func (t *textIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
defer resp.Body.Close()
if resp.StatusCode != 200 {
- return fmt.Errorf("failed to get remote file %s, http status code %d", url, resp.StatusCode)
+ return fmt.Errorf("❌ [type %s | action %s] failed to get remote file %s, http status code %d", t.Type, t.Action, url, resp.StatusCode)
}
name = strings.ToUpper(name)
diff --git a/plugin/singbox/srs_in.go b/plugin/singbox/srs_in.go
index 2a69e775..f38c53cd 100644
--- a/plugin/singbox/srs_in.go
+++ b/plugin/singbox/srs_in.go
@@ -44,11 +44,11 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
if tmp.Name == "" && tmp.URI == "" && tmp.InputDir == "" {
- return nil, fmt.Errorf("type %s | action %s missing inputdir or name or uri", typeSRSIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] missing inputdir or name or uri", typeSRSIn, action)
}
if (tmp.Name != "" && tmp.URI == "") || (tmp.Name == "" && tmp.URI != "") {
- return nil, fmt.Errorf("type %s | action %s name & uri must be specified together", typeSRSIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", typeSRSIn, action)
}
// Filter want list
@@ -109,7 +109,7 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
err = s.walkLocalFile(s.URI, s.Name, entries)
}
default:
- return nil, fmt.Errorf("config missing argument inputDir or name or uri")
+ return nil, fmt.Errorf("❌ [type %s | action %s] config missing argument inputDir or name or uri", s.Type, s.Action)
}
if err != nil {
@@ -117,7 +117,7 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("type %s | action %s no entry is generated", s.Type, s.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", s.Type, s.Action)
}
var ignoreIPType lib.IgnoreIPOption
@@ -175,7 +175,7 @@ func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
// check filename
if !regexp.MustCompile(`^[a-zA-Z0-9_.\-]+$`).MatchString(entryName) {
- return fmt.Errorf("filename %s cannot be entry name, please remove special characters in it", entryName)
+ return fmt.Errorf("❌ [type %s | action %s] filename %s cannot be entry name, please remove special characters in it", s.Type, s.Action, entryName)
}
// remove file extension but not hidden files of which filename starts with "."
@@ -187,7 +187,7 @@ func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
entryName = strings.ToUpper(entryName)
if _, found := entries[entryName]; found {
- return fmt.Errorf("found duplicated list %s", entryName)
+ return fmt.Errorf("❌ [type %s | action %s] found duplicated list %s", s.Type, s.Action, entryName)
}
file, err := os.Open(path)
@@ -211,7 +211,7 @@ func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
defer resp.Body.Close()
if resp.StatusCode != 200 {
- return fmt.Errorf("failed to get remote file %s, http status code %d", url, resp.StatusCode)
+ return fmt.Errorf("❌ [type %s | action %s] failed to get remote file %s, http status code %d", s.Type, s.Action, url, resp.StatusCode)
}
if err := s.generateEntries(name, resp.Body, entries); err != nil {
diff --git a/plugin/singbox/srs_out.go b/plugin/singbox/srs_out.go
index 877e5acd..d2950ee5 100644
--- a/plugin/singbox/srs_out.go
+++ b/plugin/singbox/srs_out.go
@@ -175,7 +175,7 @@ func (s *srsOut) generateRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error)
return &plainRuleSet, nil
}
- return nil, fmt.Errorf("entry %s has no CIDR", entry.GetName())
+ return nil, fmt.Errorf("❌ [type %s | action %s] entry %s has no CIDR", s.Type, s.Action, entry.GetName())
}
func (s *srsOut) writeFile(filename string, ruleset *option.PlainRuleSet) error {
diff --git a/plugin/special/cutter.go b/plugin/special/cutter.go
index 2d52e161..2b33ee27 100644
--- a/plugin/special/cutter.go
+++ b/plugin/special/cutter.go
@@ -35,7 +35,7 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err
}
if action != lib.ActionRemove {
- return nil, fmt.Errorf("type %s only supports `remove` action", typeCutter)
+ return nil, fmt.Errorf("❌ [type %s] only supports `remove` action", typeCutter)
}
// Filter want list
@@ -47,7 +47,7 @@ func newCutter(action lib.Action, data json.RawMessage) (lib.InputConverter, err
}
if len(wantList) == 0 {
- return nil, fmt.Errorf("type %s wantedList must be specified", typeCutter)
+ return nil, fmt.Errorf("❌ [type %s] wantedList must be specified", typeCutter)
}
return &cutter{
diff --git a/plugin/special/lookup.go b/plugin/special/lookup.go
index 7c97e746..34ba0207 100644
--- a/plugin/special/lookup.go
+++ b/plugin/special/lookup.go
@@ -38,7 +38,7 @@ func newLookup(action lib.Action, data json.RawMessage) (lib.OutputConverter, er
tmp.Search = strings.TrimSpace(tmp.Search)
if tmp.Search == "" {
- return nil, fmt.Errorf("type %s | action %s: please specify an IP or a CIDR as search target", typeLookup, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] please specify an IP or a CIDR as search target", typeLookup, action)
}
return &lookup{
diff --git a/plugin/special/stdin.go b/plugin/special/stdin.go
index 4f56d756..1621c351 100644
--- a/plugin/special/stdin.go
+++ b/plugin/special/stdin.go
@@ -37,7 +37,7 @@ func newStdin(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
if tmp.Name == "" {
- return nil, fmt.Errorf("type %s | action %s missing name", typeStdin, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] missing name", typeStdin, action)
}
return &stdin{
diff --git a/plugin/v2ray/dat_in.go b/plugin/v2ray/dat_in.go
index 4b2a98c0..96de3d70 100644
--- a/plugin/v2ray/dat_in.go
+++ b/plugin/v2ray/dat_in.go
@@ -42,7 +42,7 @@ func newGeoIPDatIn(action lib.Action, data json.RawMessage) (lib.InputConverter,
}
if tmp.URI == "" {
- return nil, fmt.Errorf("[type %s | action %s] uri must be specified in config", typeGeoIPdatIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] uri must be specified in config", typeGeoIPdatIn, action)
}
// Filter want list
@@ -100,7 +100,7 @@ func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeGeoIPdatIn, g.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", g.Type, g.Action)
}
var ignoreIPType lib.IgnoreIPOption
@@ -151,7 +151,7 @@ func (g *geoIPDatIn) walkRemoteFile(url string, entries map[string]*lib.Entry) e
defer resp.Body.Close()
if resp.StatusCode != 200 {
- return fmt.Errorf("failed to get remote file %s, http status code %d", url, resp.StatusCode)
+ return fmt.Errorf("❌ [type %s | action %s] failed to get remote file %s, http status code %d", g.Type, g.Action, url, resp.StatusCode)
}
if err := g.generateEntries(resp.Body, entries); err != nil {
diff --git a/plugin/v2ray/dat_out.go b/plugin/v2ray/dat_out.go
index abb00ca4..771d4e27 100644
--- a/plugin/v2ray/dat_out.go
+++ b/plugin/v2ray/dat_out.go
@@ -219,7 +219,7 @@ func (g *geoIPDatOut) generateGeoIP(entry *lib.Entry) (*router.GeoIP, error) {
}, nil
}
- return nil, fmt.Errorf("entry %s has no CIDR", entry.GetName())
+ return nil, fmt.Errorf("❌ [type %s | action %s] entry %s has no CIDR", g.Type, g.Action, entry.GetName())
}
// Sort by country code to make reproducible builds