Skip to content

Commit cda9a9b

Browse files
yongjiajunnabeken
andcommitted
refactor: Prefix error message with package name
Co-Authored-By: Tanabe Ken-ichi <nabeken@tknetworks.org>
1 parent 7773ea5 commit cda9a9b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

spf2ip.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const (
1919
)
2020

2121
var (
22-
ErrInvalidIPVersion = errors.New("invalid IP version specified, must be 4 or 6")
23-
ErrLoopDetected = errors.New("loop detected in SPF resolution")
24-
ErrExceededMaxDepth = errors.New("maximum SPF include depth exceeded")
22+
ErrInvalidIPVersion = errors.New("spf2ip: invalid IP version specified, must be 4 or 6")
23+
ErrLoopDetected = errors.New("spf2ip: loop detected in SPF resolution")
24+
ErrExceededMaxDepth = errors.New("spf2ip: maximum SPF include depth exceeded")
2525
)
2626

2727
type SPF2IPResolver struct {
@@ -108,7 +108,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
108108
r.debugLogPrintf("Debug: Failed to get SPF record for %s: %v", domain, err)
109109
r.resolvedIPsCache[domain] = nil
110110

111-
return nil, fmt.Errorf("failed to get SPF record for %s: %w", domain, err)
111+
return nil, fmt.Errorf("spf2ip: failed to get SPF record for %s: %w", domain, err)
112112
}
113113

114114
if spfString == "" {
@@ -142,14 +142,14 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
142142
case "ip4":
143143
if r.ipVersion == ipv4 {
144144
if err := r.addIPOrCIDRToSet(value, currentDomainIPs); err != nil {
145-
return nil, fmt.Errorf("failed to add IP/CIDR for ip4 mechanism in %s: %w", domain, err)
145+
return nil, fmt.Errorf("spf2ip: failed to add IP/CIDR for ip4 mechanism in %s: %w", domain, err)
146146
}
147147
}
148148

149149
case "ip6":
150150
if r.ipVersion == ipv6 {
151151
if err := r.addIPOrCIDRToSet(value, currentDomainIPs); err != nil {
152-
return nil, fmt.Errorf("failed to add IP/CIDR for ip6 mechanism in %s: %w", domain, err)
152+
return nil, fmt.Errorf("spf2ip: failed to add IP/CIDR for ip6 mechanism in %s: %w", domain, err)
153153
}
154154
}
155155

@@ -168,7 +168,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
168168

169169
for _, ip := range ips {
170170
if err := r.addIPOrCIDRToSet(ip.String()+maskSuffix, currentDomainIPs); err != nil {
171-
return nil, fmt.Errorf("failed to add IP/CIDR for A mechanism in %s: %w", domain, err)
171+
return nil, fmt.Errorf("spf2ip: failed to add IP/CIDR for A mechanism in %s: %w", domain, err)
172172
}
173173
}
174174

@@ -182,7 +182,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
182182
continue
183183
}
184184

185-
return nil, fmt.Errorf("MX lookup failed for %s (directive in %s): %w", targetHost, domain, err)
185+
return nil, fmt.Errorf("spf2ip: MX lookup failed for %s (directive in %s): %w", targetHost, domain, err)
186186
}
187187

188188
for _, mx := range mxs {
@@ -201,7 +201,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
201201

202202
for _, ip := range ips {
203203
if err := r.addIPOrCIDRToSet(ip.String()+maskSuffix, currentDomainIPs); err != nil {
204-
return nil, fmt.Errorf("failed to add IP/CIDR for MX mechanism in %s: %w", domain, err)
204+
return nil, fmt.Errorf("spf2ip: failed to add IP/CIDR for MX mechanism in %s: %w", domain, err)
205205
}
206206
}
207207
}
@@ -211,12 +211,12 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
211211
r.debugLogPrintf("Debug: 'include' modifier without domain in %s", domain)
212212
r.resolvedIPsCache[domain] = nil
213213

214-
return nil, fmt.Errorf("include without domain in %s", domain)
214+
return nil, fmt.Errorf("spf2ip: include without domain in %s", domain)
215215
}
216216

217217
includedIPs, includeErr := r.processDomain(ctx, value, depth+1)
218218
if includeErr != nil {
219-
return nil, fmt.Errorf("include failed for %s (directive in %s): %w", value, domain, includeErr)
219+
return nil, fmt.Errorf("spf2ip: include failed for %s (directive in %s): %w", value, domain, includeErr)
220220
}
221221

222222
for ip := range includedIPs {
@@ -228,7 +228,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
228228
r.debugLogPrintf("Debug: 'redirect' modifier without domain in %s", domain)
229229
r.resolvedIPsCache[domain] = nil
230230

231-
return nil, fmt.Errorf("redirect without domain in %s", domain)
231+
return nil, fmt.Errorf("spf2ip: redirect without domain in %s", domain)
232232
}
233233

234234
r.debugLogPrintf("Debug: Redirecting from %s to %s. Discarding IPs found so far for %s.", domain, value, domain)
@@ -290,8 +290,8 @@ func parseSPFMechanismTargetAndMask(defaultDomain, mechanismValue string) (targe
290290
}
291291

292292
var (
293-
errIgnorableDNSErr = errors.New("ignorable DNS error")
294-
errDNSErr = errors.New("DNS error")
293+
errIgnorableDNSErr = errors.New("spf2ip: ignorable DNS error")
294+
errDNSErr = errors.New("spf2ip: DNS error")
295295
)
296296

297297
func (r *SPF2IPResolver) getSPFRecord(ctx context.Context, domain string) (string, error) {
@@ -329,7 +329,7 @@ func (r *SPF2IPResolver) addIPOrCIDRToSet(value string, targetSet map[string]str
329329
return nil
330330
}
331331

332-
return fmt.Errorf("CIDR '%s' is not of the required IP version (v%d)", value, r.ipVersion)
332+
return fmt.Errorf("spf2ip: CIDR '%s' is not of the required IP version (v%d)", value, r.ipVersion)
333333
}
334334

335335
// Try plain IP
@@ -347,10 +347,10 @@ func (r *SPF2IPResolver) addIPOrCIDRToSet(value string, targetSet map[string]str
347347
return nil
348348
}
349349

350-
return fmt.Errorf("IP address '%s' is not of the required IP version (v%d)", value, r.ipVersion)
350+
return fmt.Errorf("spf2ip: IP address '%s' is not of the required IP version (v%d)", value, r.ipVersion)
351351
}
352352

353-
return fmt.Errorf("value '%s' is not a valid IP address or CIDR block", value)
353+
return fmt.Errorf("spf2ip: value '%s' is not a valid IP address or CIDR block", value)
354354
}
355355

356356
// debugLogPrintf logs debug messages if debug logging is enabled.

0 commit comments

Comments
 (0)