refactor(trace): 把剥 url.Error 壳的实现收敛成 trace.URLCause
五处逐字同形的三行(mediafetch.sanitizeErr / httpclient.transportCause / vision.fetchCause / telegram.callCause / weixin_ilink.urlFreeCause)收敛为 trace 包里的唯一实现,13 个调用点改为直接调用;5 份 body 只剩 1 份,5 个 未导出符号与其文件内注释整份删除(不留薄封装)。 行为等价:只剥 *url.Error、不新增包装,内层哨兵链(context 取消/超时、 *net.DNSError 等)原样透传,因此重试/降级/熔断的分类判据不变。两处刻意的 收紧: - 逐层剥:内层若还是 *url.Error 也一起剥(只剥一层时内层仍带同一段地址); - *url.Error 的 Err 为 nil(或链自引用)时不再回落到原串,退化成只含 Op 的 替身 —— 那种错误无法在不带地址的前提下原样返回,而地址里就是凭据。 顺带把 httpclient 的 user:pass@ 用例改成变异可打红:net/http 自己在 *url.Error 里就把密码打成 ***,「密码不出现」在剥壳与不剥壳下都成立(空跑), 用户名才是分水岭。 验收:go build ./... + go vet ./... + 指定包 go test -count=1 全绿; 变异验证(把 URLCause 改成透传)⇒ 五处「不含 URL」断言全红。
This commit is contained in:
1 parent
af61b8ccfe
commit
4c187ac070
10 files changed
+249
-81
No files matched your search
@@ -32,6 +32,7 @@ import (
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/mediafetch"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -232,12 +233,12 @@ func (a *Adapter) uploadOnce(ctx context.Context, uploadURL string, data []byte)
|
||||
host := mediafetch.HostOf(uploadURL)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uploadURL, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("weixin_ilink: build upload to %s: %w", host, urlFreeCause(err))
|
||||
return "", false, fmt.Errorf("weixin_ilink: build upload to %s: %w", host, trace.URLCause(err))
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/octet-stream")
|
||||
resp, err := a.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return "", true, fmt.Errorf("weixin_ilink: upload media to %s: %w", host, urlFreeCause(err))
|
||||
return "", true, fmt.Errorf("weixin_ilink: upload media to %s: %w", host, trace.URLCause(err))
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
Reference in new issue
Block a user