Skip to content

Commit 8e599bb

Browse files
committed
fix: use %w instead of %s
1 parent 27d8c81 commit 8e599bb

25 files changed

Lines changed: 69 additions & 69 deletions

File tree

client/connection.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@ type ExecutionResponse interface {
105105
func Execute(ctx context.Context, invocations []invocation.Invocation, conn Connection) (ExecutionResponse, error) {
106106
input, err := message.Build(invocations, nil)
107107
if err != nil {
108-
return nil, fmt.Errorf("building message: %s", err)
108+
return nil, fmt.Errorf("building message: %w", err)
109109
}
110110

111111
req, err := conn.Codec().Encode(input)
112112
if err != nil {
113-
return nil, fmt.Errorf("encoding message: %s", err)
113+
return nil, fmt.Errorf("encoding message: %w", err)
114114
}
115115

116116
res, err := conn.Channel().Request(ctx, req)
117117
if err != nil {
118-
return nil, fmt.Errorf("sending message: %s", err)
118+
return nil, fmt.Errorf("sending message: %w", err)
119119
}
120120

121121
output, err := conn.Codec().Decode(res)
122122
if err != nil {
123-
return nil, fmt.Errorf("decoding message: %s", err)
123+
return nil, fmt.Errorf("decoding message: %w", err)
124124
}
125125

126126
return ExecutionResponse(output), nil

core/car/car.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Encode(roots []ipld.Link, blocks iter.Seq2[ipld.Block, error]) io.Reader {
2727
for _, r := range roots {
2828
_, cid, err := cid.CidFromBytes([]byte(r.Binary()))
2929
if err != nil {
30-
writer.CloseWithError(fmt.Errorf("decoding CAR root: %s: %s", r, err))
30+
writer.CloseWithError(fmt.Errorf("decoding CAR root: %s: %w", r, err))
3131
return
3232
}
3333
cids = append(cids, cid)
@@ -38,18 +38,18 @@ func Encode(roots []ipld.Link, blocks iter.Seq2[ipld.Block, error]) io.Reader {
3838
}
3939
hb, err := cbor.DumpObject(h)
4040
if err != nil {
41-
writer.CloseWithError(fmt.Errorf("writing CAR header: %s", err))
41+
writer.CloseWithError(fmt.Errorf("writing CAR header: %w", err))
4242
return
4343
}
4444
util.LdWrite(writer, hb)
4545
for block, err := range blocks {
4646
if err != nil {
47-
writer.CloseWithError(fmt.Errorf("writing CAR blocks: %s", err))
47+
writer.CloseWithError(fmt.Errorf("writing CAR blocks: %w", err))
4848
return
4949
}
5050
err = util.LdWrite(writer, []byte(block.Link().Binary()), block.Bytes())
5151
if err != nil {
52-
writer.CloseWithError(fmt.Errorf("writing CAR blocks: %s", err))
52+
writer.CloseWithError(fmt.Errorf("writing CAR blocks: %w", err))
5353
return
5454
}
5555
}

core/dag/blockstore/blockstore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func WriteInto(view ipld.View, bs BlockWriter) error {
187187
for b := range view.Blocks() {
188188
err := bs.Put(b)
189189
if err != nil {
190-
return fmt.Errorf("putting proof block: %s", err)
190+
return fmt.Errorf("putting proof block: %w", err)
191191
}
192192
}
193193
return nil

core/delegation/datamodel/archive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func mustLoadSchema() *schema.TypeSystem {
2323
ts, err = ipld.LoadSchemaBytes(archive)
2424
})
2525
if err != nil {
26-
panic(fmt.Errorf("failed to load IPLD schema: %s", err))
26+
panic(fmt.Errorf("failed to load IPLD schema: %w", err))
2727
}
2828
return ts
2929
}

core/delegation/datamodel/archive_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func TestEncodeDecode(t *testing.T) {
1818
}
1919
mblk, err := block.Encode(&m0, adm.Type(), cbor.Codec, sha256.Hasher)
2020
if err != nil {
21-
t.Fatalf("encoding archive model: %s", err)
21+
t.Fatalf("encoding archive model: %w", err)
2222
}
2323

2424
m1 := adm.ArchiveModel{}
2525
err = block.Decode(mblk, &m1, adm.Type(), cbor.Codec, sha256.Hasher)
2626
if err != nil {
27-
t.Fatalf("decoding agent message: %s", err)
27+
t.Fatalf("decoding agent message: %w", err)
2828
}
2929

3030
d1 := m1.Ucan0_9_1

core/delegation/delegate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ func Delegate[C ucan.CaveatBuilder](issuer ucan.Signer, audience ucan.Principal,
116116

117117
data, err := ucan.Issue(issuer, audience, capabilities, opts...)
118118
if err != nil {
119-
return nil, fmt.Errorf("issuing UCAN: %s", err)
119+
return nil, fmt.Errorf("issuing UCAN: %w", err)
120120
}
121121

122122
rt, err := block.Encode(data.Model(), udm.Type(), cbor.Codec, sha256.Hasher)
123123
if err != nil {
124-
return nil, fmt.Errorf("encoding UCAN: %s", err)
124+
return nil, fmt.Errorf("encoding UCAN: %w", err)
125125
}
126126

127127
err = bs.Put(rt)
128128
if err != nil {
129-
return nil, fmt.Errorf("adding delegation root to store: %s", err)
129+
return nil, fmt.Errorf("adding delegation root to store: %w", err)
130130
}
131131

132132
return NewDelegation(rt, bs)

core/delegation/delegation.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (d *delegation) Attach(b block.Block) error {
115115
func NewDelegation(root ipld.Block, bs blockstore.BlockReader) (Delegation, error) {
116116
ucan, err := decode(root)
117117
if err != nil {
118-
return nil, fmt.Errorf("decoding UCAN: %s", err)
118+
return nil, fmt.Errorf("decoding UCAN: %w", err)
119119
}
120120
attachments, err := blockstore.NewBlockStore()
121121
if err != nil {
@@ -127,7 +127,7 @@ func NewDelegation(root ipld.Block, bs blockstore.BlockReader) (Delegation, erro
127127
func NewDelegationView(root ipld.Link, bs blockstore.BlockReader) (Delegation, error) {
128128
blk, ok, err := bs.Get(root)
129129
if err != nil {
130-
return nil, fmt.Errorf("getting delegation root block: %s", err)
130+
return nil, fmt.Errorf("getting delegation root block: %w", err)
131131
}
132132
if !ok {
133133
return nil, fmt.Errorf("missing delegation root block: %s", root)
@@ -201,20 +201,20 @@ func Archive(d Delegation) io.Reader {
201201
)
202202
if err != nil {
203203
reader, _ := io.Pipe()
204-
reader.CloseWithError(fmt.Errorf("hashing variant block bytes: %s", err))
204+
reader.CloseWithError(fmt.Errorf("hashing variant block bytes: %w", err))
205205
return reader
206206
}
207207
// Create a new reader that contains the new block as well as the others.
208208
blks, err := blockstore.NewBlockStore(blockstore.WithBlocksIterator(d.Blocks()))
209209
if err != nil {
210210
reader, _ := io.Pipe()
211-
reader.CloseWithError(fmt.Errorf("creating new block reader: %s", err))
211+
reader.CloseWithError(fmt.Errorf("creating new block reader: %w", err))
212212
return reader
213213
}
214214
err = blks.Put(variant)
215215
if err != nil {
216216
reader, _ := io.Pipe()
217-
reader.CloseWithError(fmt.Errorf("adding variant block: %s", err))
217+
reader.CloseWithError(fmt.Errorf("adding variant block: %w", err))
218218
return reader
219219
}
220220
return car.Encode([]ipld.Link{variant.Link()}, blks.Iterator())
@@ -234,15 +234,15 @@ func Extract(b []byte) (Delegation, error) {
234234

235235
br, err := blockstore.NewBlockReader(blockstore.WithBlocksIterator(blks))
236236
if err != nil {
237-
return nil, fmt.Errorf("creating block reader: %s", err)
237+
return nil, fmt.Errorf("creating block reader: %w", err)
238238
}
239239

240240
rt, ok, err := br.Get(roots[0])
241241
if err != nil {
242-
return nil, fmt.Errorf("getting root block: %s", err)
242+
return nil, fmt.Errorf("getting root block: %w", err)
243243
}
244244
if !ok {
245-
return nil, fmt.Errorf("missing root block: %d", len(roots))
245+
return nil, fmt.Errorf("missing root block: %s", roots[0])
246246
}
247247

248248
model := adm.ArchiveModel{}
@@ -254,7 +254,7 @@ func Extract(b []byte) (Delegation, error) {
254254
sha256.Hasher,
255255
)
256256
if err != nil {
257-
return nil, fmt.Errorf("decoding root block: %s", err)
257+
return nil, fmt.Errorf("decoding root block: %w", err)
258258
}
259259

260260
return NewDelegationView(model.Ucan0_9_1, br)

core/message/datamodel/agentmessage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func mustLoadSchema() *schema.TypeSystem {
2323
ts, err = ipld.LoadSchemaBytes(agentmessage)
2424
})
2525
if err != nil {
26-
panic(fmt.Errorf("failed to load IPLD schema: %s", err))
26+
panic(fmt.Errorf("failed to load IPLD schema: %w", err))
2727
}
2828
return ts
2929
}

core/message/message.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func NewMessage(roots []ipld.Link, blks blockstore.BlockReader) (AgentMessage, e
140140

141141
rblock, ok, err := blks.Get(roots[0])
142142
if err != nil {
143-
return nil, fmt.Errorf("getting root block: %s", err)
143+
return nil, fmt.Errorf("getting root block: %w", err)
144144
}
145145
if !ok {
146146
return nil, fmt.Errorf("missing root block: %s", roots[0])
@@ -155,7 +155,7 @@ func NewMessage(roots []ipld.Link, blks blockstore.BlockReader) (AgentMessage, e
155155
sha256.Hasher,
156156
)
157157
if err != nil {
158-
return nil, fmt.Errorf("decoding message: %s", err)
158+
return nil, fmt.Errorf("decoding message: %w", err)
159159
}
160160

161161
return &message{root: rblock, data: msg.UcantoMessage7, blks: blks}, nil

core/receipt/datamodel/receipt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var anyReceiptTs *schema.TypeSystem
2424
func init() {
2525
ts, err := NewReceiptModelType(anyResultSchema)
2626
if err != nil {
27-
panic(fmt.Errorf("failed to load IPLD schema: %s", err))
27+
panic(fmt.Errorf("failed to load IPLD schema: %w", err))
2828
}
2929
anyReceiptTs = ts.TypeSystem()
3030
}

0 commit comments

Comments
 (0)