Skip to content

Commit ef0b052

Browse files
committed
fix: make mss check logger before use (#2261)
Check logger is present before use. This should have gone out as a breaking change.
1 parent d539109 commit ef0b052

File tree

6 files changed

+76
-75
lines changed

6 files changed

+76
-75
lines changed

.github/workflows/examples.yml

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@ jobs:
1919
node-version: lts/*
2020
- uses: ipfs/aegir/actions/cache-node-modules@master
2121

22-
test-examples:
23-
name: Test example ${{ matrix.example.name }}
24-
runs-on: ubuntu-latest
25-
needs: build
26-
continue-on-error: true
27-
strategy:
28-
matrix:
29-
example:
30-
- name: js-libp2p-example-chat
31-
repo: https://github.com/libp2p/js-libp2p-example-chat.git
32-
deps:
33-
- '@libp2p/peer-id-factory@$PWD/packages/peer-id-factory'
34-
- '@libp2p/tcp@$PWD/packages/transport-tcp'
35-
- '@libp2p/websockets@$PWD/packages/transport-websockets'
36-
- 'libp2p@$PWD/packages/libp2p'
37-
# disabled until @libp2p/identify and @libp2p/circuit-relay are published
38-
# - name: js-libp2p-example-circuit-relay
39-
# repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git
40-
# deps:
41-
# - '@libp2p/circuit-relay@$PWD/packages/transport-circuit-relay'
42-
# - '@libp2p/identify@$PWD/packages/protocol-identify'
43-
# - '@libp2p/websockets@$PWD/packages/transport-websockets'
44-
# - 'libp2p@$PWD/packages/libp2p'
45-
- name: js-libp2p-example-connection-encryption
46-
repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git
47-
deps:
48-
- '@libp2p/tcp@$PWD/packages/transport-tcp'
49-
- 'libp2p@$PWD/packages/libp2p'
50-
steps:
51-
- uses: actions/checkout@v3
52-
- uses: actions/setup-node@v3
53-
with:
54-
node-version: lts/*
55-
- uses: ipfs/aegir/actions/cache-node-modules@master
56-
- run: npx xvfb-maybe aegir test-dependant ${{ matrix.example.repo }} --deps ${{ join(matrix.example.deps, ',') }}
22+
# test-examples:
23+
# name: Test example ${{ matrix.example.name }}
24+
# runs-on: ubuntu-latest
25+
# needs: build
26+
# continue-on-error: true
27+
# strategy:
28+
# matrix:
29+
# example:
30+
# - name: js-libp2p-example-chat
31+
# repo: https://github.com/libp2p/js-libp2p-example-chat.git
32+
# deps:
33+
# - '@libp2p/peer-id-factory@$PWD/packages/peer-id-factory'
34+
# - '@libp2p/tcp@$PWD/packages/transport-tcp'
35+
# - '@libp2p/websockets@$PWD/packages/transport-websockets'
36+
# - 'libp2p@$PWD/packages/libp2p'
37+
# # disabled until @libp2p/identify and @libp2p/circuit-relay are published
38+
# # - name: js-libp2p-example-circuit-relay
39+
# # repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git
40+
# # deps:
41+
# # - '@libp2p/circuit-relay@$PWD/packages/transport-circuit-relay'
42+
# # - '@libp2p/identify@$PWD/packages/protocol-identify'
43+
# # - '@libp2p/websockets@$PWD/packages/transport-websockets'
44+
# # - 'libp2p@$PWD/packages/libp2p'
45+
# - name: js-libp2p-example-connection-encryption
46+
# repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git
47+
# deps:
48+
# - '@libp2p/tcp@$PWD/packages/transport-tcp'
49+
# - 'libp2p@$PWD/packages/libp2p'
50+
# steps:
51+
# - uses: actions/checkout@v3
52+
# - uses: actions/setup-node@v3
53+
# with:
54+
# node-version: lts/*
55+
# - uses: ipfs/aegir/actions/cache-node-modules@master
56+
# - run: npx xvfb-maybe aegir test-dependant ${{ matrix.example.repo }} --deps ${{ join(matrix.example.deps, ',') }}

.github/workflows/main.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,20 @@ jobs:
218218
transport-interop
219219
]
220220
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
221-
# https://docs.npmjs.com/generating-provenance-statements
222221
permissions:
223222
id-token: write
224223
contents: write
224+
pull-requests: write
225225
steps:
226-
- uses: GoogleCloudPlatform/release-please-action@v2
226+
- uses: google-github-actions/release-please-action@v3
227227
id: release
228228
with:
229-
token: ${{ secrets.GITHUB_TOKEN }}
230-
command: manifest
229+
token: ${{ secrets.UCI_GITHUB_TOKEN || github.token }}
231230
release-type: node
232-
manifest-file: .release-please-manifest.json
233-
config-file: .release-please.json
231+
monorepo-tags: true
232+
last-release-sha: a7eb258e0ef2147671acba73d9febc2f882a484a
233+
group-pull-request-title-pattern: "chore: release ${component}"
234+
tag-separator: '@'
234235
changelog-types: |
235236
[
236237
{ "type": "feat", "section": "Features", "hidden": false },

.release-please.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"last-release-sha": "17d980c902fa5314e954508255a41c0854416d47",
2+
"last-release-sha": "d5391097b6d7daf24346b3cb2899ae808f1cb0de",
33
"plugins": ["node-workspace"],
44
"group-pull-request-title-pattern": "chore: release ${component}",
55
"packages": {

packages/multistream-select/src/handle.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import type { Duplex } from 'it-stream-types'
5555
*/
5656
export async function handle <Stream extends Duplex<any, any, any>> (stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>> {
5757
protocols = Array.isArray(protocols) ? protocols : [protocols]
58-
options.log.trace('handle: available protocols %s', protocols)
58+
options?.log?.trace('handle: available protocols %s', protocols)
5959

6060
const lp = lpStream(stream, {
6161
...options,
@@ -64,21 +64,21 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
6464
})
6565

6666
while (true) {
67-
options?.log.trace('handle: reading incoming string')
67+
options?.log?.trace('handle: reading incoming string')
6868
const protocol = await multistream.readString(lp, options)
69-
options.log.trace('handle: read "%s"', protocol)
69+
options?.log?.trace('handle: read "%s"', protocol)
7070

7171
if (protocol === PROTOCOL_ID) {
72-
options.log.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
72+
options?.log?.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
7373
await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options)
74-
options.log.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
74+
options?.log?.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
7575
continue
7676
}
7777

7878
if (protocols.includes(protocol)) {
79-
options.log.trace('handle: respond with "%s" for "%s"', protocol, protocol)
79+
options?.log?.trace('handle: respond with "%s" for "%s"', protocol, protocol)
8080
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
81-
options.log.trace('handle: responded with "%s" for "%s"', protocol, protocol)
81+
options?.log?.trace('handle: responded with "%s" for "%s"', protocol, protocol)
8282

8383
return { stream: lp.unwrap(), protocol }
8484
}
@@ -90,14 +90,14 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
9090
uint8ArrayFromString('\n')
9191
)
9292

93-
options.log.trace('handle: respond with "%s" for %s', protocols, protocol)
93+
options?.log?.trace('handle: respond with "%s" for %s', protocols, protocol)
9494
await multistream.write(lp, protos, options)
95-
options.log.trace('handle: responded with "%s" for %s', protocols, protocol)
95+
options?.log?.trace('handle: responded with "%s" for %s', protocols, protocol)
9696
continue
9797
}
9898

99-
options.log('handle: respond with "na" for "%s"', protocol)
99+
options?.log?.('handle: respond with "na" for "%s"', protocol)
100100
await multistream.write(lp, uint8ArrayFromString('na\n'), options)
101-
options.log('handle: responded with "na" for "%s"', protocol)
101+
options?.log?.('handle: responded with "na" for "%s"', protocol)
102102
}
103103
}

packages/multistream-select/src/multistream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function read (reader: LengthPrefixedStream<Duplex<AsyncGenerator<U
3030
const buf = await reader.read(options)
3131

3232
if (buf.byteLength === 0 || buf.get(buf.byteLength - 1) !== NewLine[0]) {
33-
options?.log.error('Invalid mss message - missing newline', buf)
33+
options?.log?.error('Invalid mss message - missing newline', buf)
3434
throw new CodeError('missing newline', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
3535
}
3636

packages/multistream-select/src/select.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
7878
throw new Error('At least one protocol must be specified')
7979
}
8080

81-
options?.log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
81+
options?.log?.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
8282
const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`)
8383
const p2 = uint8ArrayFromString(`${protocol}\n`)
8484
await multistream.writeAll(lp, [p1, p2], options)
8585

86-
options?.log.trace('select: reading multistream-select header')
86+
options?.log?.trace('select: reading multistream-select header')
8787
let response = await multistream.readString(lp, options)
88-
options?.log.trace('select: read "%s"', response)
88+
options?.log?.trace('select: read "%s"', response)
8989

9090
// Read the protocol response if we got the protocolId in return
9191
if (response === PROTOCOL_ID) {
92-
options?.log.trace('select: reading protocol response')
92+
options?.log?.trace('select: reading protocol response')
9393
response = await multistream.readString(lp, options)
94-
options?.log.trace('select: read "%s"', response)
94+
options?.log?.trace('select: read "%s"', response)
9595
}
9696

9797
// We're done
@@ -101,11 +101,11 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
101101

102102
// We haven't gotten a valid ack, try the other protocols
103103
for (const protocol of protocols) {
104-
options?.log.trace('select: write "%s"', protocol)
104+
options?.log?.trace('select: write "%s"', protocol)
105105
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
106-
options?.log.trace('select: reading protocol response')
106+
options?.log?.trace('select: reading protocol response')
107107
const response = await multistream.readString(lp, options)
108-
options?.log.trace('select: read "%s" for "%s"', response, protocol)
108+
options?.log?.trace('select: read "%s" for "%s"', response, protocol)
109109

110110
if (response === protocol) {
111111
return { stream: lp.unwrap(), protocol }
@@ -163,7 +163,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
163163
if (!sentProtocol) {
164164
sendingProtocol = true
165165

166-
options?.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
166+
options?.log?.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
167167

168168
const protocolString = `${protocol}\n`
169169

@@ -176,7 +176,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
176176
buf
177177
).subarray()
178178

179-
options?.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
179+
options?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
180180

181181
sentProtocol = true
182182
sendingProtocol = false
@@ -198,7 +198,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
198198

199199
async function negotiate (): Promise<void> {
200200
if (negotiating) {
201-
options?.log.trace('optimistic: already negotiating %s stream', protocol)
201+
options?.log?.trace('optimistic: already negotiating %s stream', protocol)
202202
await doneNegotiating.promise
203203
return
204204
}
@@ -208,13 +208,13 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
208208
try {
209209
// we haven't sent the protocol yet, send it now
210210
if (!sentProtocol) {
211-
options?.log.trace('optimistic: doing send protocol for %s stream', protocol)
211+
options?.log?.trace('optimistic: doing send protocol for %s stream', protocol)
212212
await doSendProtocol()
213213
}
214214

215215
// if we haven't read the protocol response yet, do it now
216216
if (!readProtocol) {
217-
options?.log.trace('optimistic: doing read protocol for %s stream', protocol)
217+
options?.log?.trace('optimistic: doing read protocol for %s stream', protocol)
218218
await doReadProtocol()
219219
}
220220
} finally {
@@ -233,12 +233,12 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
233233
sendingProtocol = true
234234

235235
try {
236-
options?.log.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
236+
options?.log?.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
237237
await lp.writeV([
238238
uint8ArrayFromString(`${PROTOCOL_ID}\n`),
239239
uint8ArrayFromString(`${protocol}\n`)
240240
])
241-
options?.log.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
241+
options?.log?.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
242242
} finally {
243243
sentProtocol = true
244244
sendingProtocol = false
@@ -255,15 +255,15 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
255255
readingProtocol = true
256256

257257
try {
258-
options?.log.trace('optimistic: reading multistream select header')
258+
options?.log?.trace('optimistic: reading multistream select header')
259259
let response = await multistream.readString(lp, options)
260-
options?.log.trace('optimistic: read multistream select header "%s"', response)
260+
options?.log?.trace('optimistic: read multistream select header "%s"', response)
261261

262262
if (response === PROTOCOL_ID) {
263263
response = await multistream.readString(lp, options)
264264
}
265265

266-
options?.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol)
266+
options?.log?.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol)
267267

268268
if (response !== protocol) {
269269
throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL')
@@ -279,7 +279,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
279279
// make sure we've done protocol negotiation before we read stream data
280280
await negotiate()
281281

282-
options?.log.trace('optimistic: reading data from "%s" stream', protocol)
282+
options?.log?.trace('optimistic: reading data from "%s" stream', protocol)
283283
yield * lp.unwrap().source
284284
})()
285285

@@ -291,7 +291,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
291291
// this before closing the readable end of the stream
292292
if (!negotiated) {
293293
await negotiate().catch(err => {
294-
options?.log.error('could not negotiate protocol before close read', err)
294+
options?.log?.error('could not negotiate protocol before close read', err)
295295
})
296296
}
297297

@@ -308,7 +308,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
308308
// this before closing the writable end of the stream
309309
if (!negotiated) {
310310
await negotiate().catch(err => {
311-
options?.log.error('could not negotiate protocol before close write', err)
311+
options?.log?.error('could not negotiate protocol before close write', err)
312312
})
313313
}
314314

0 commit comments

Comments
 (0)