WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2029981

Browse files
committed
chore: SAVEPOINT
1 parent b9fe9ce commit 2029981

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
"pear-link": "^4.1.0",
106106
"pear-logger": "^1.0.0",
107107
"pear-pipe": "^1.0.1",
108-
"pear-run": "^1.0.8",
109108
"pear-shake": "^2.0.1",
110109
"pear-stamp": "^1.0.1",
111110
"pear-state": "^1.0.2",

subsystems/sidecar/lib/opstream.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ module.exports = class Opstream extends streamx.Readable {
2424
if (autosession) return this.session.close()
2525
}
2626

27-
if (params.link) params.link = plink.normalize(params.link)
27+
if (params.link) {
28+
try {
29+
params.link = plink.normalize(params.link)
30+
} catch (e) {
31+
e.code = 'INVALID_LINK'
32+
error(e)
33+
return close()
34+
}
35+
}
2836
op(params).catch(error).finally(close)
2937
}
3038
})

test/14-preflight.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test('preflight downloads staged assets', async (t) => {
9292
await helper.ready()
9393

9494
await t.execution(
95-
new Promise((resolve) => {
95+
new Promise((resolve, reject) => {
9696
const timeoutId = setTimeout(() => reject(new Error('timed out')), 500)
9797
pipe.once('data', () => {
9898
reject(new Error('unexpected data'))

test/15-opstream.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const test = require('brittle')
2+
const Helper = require('./helper')
3+
const ops = require('../subsystems/sidecar/ops')
4+
5+
test('running ops with invalid link param does not crash the sidecar', async (t) => {
6+
const opMethods = [
7+
'data',
8+
'drop',
9+
'dump',
10+
'gc',
11+
'info',
12+
'release',
13+
'run',
14+
'seed',
15+
'shift',
16+
'stage',
17+
'touch'
18+
]
19+
t.plan(opMethods.length * 2)
20+
21+
const helper = new Helper()
22+
t.teardown(() => helper.close(), { order: Infinity })
23+
await helper.ready()
24+
25+
for (const method of opMethods) {
26+
const testOp = async () => {
27+
const params = { link: { id: 'not-a-link' } }
28+
const stream = helper[method](params)
29+
try {
30+
await Helper.pick(stream, { tag: 'final' })
31+
t.fail('expected op to fail (op passed)')
32+
} catch (e) {
33+
if (e.code === 'INVALID_LINK') {
34+
t.pass()
35+
} else {
36+
t.fail('expected op to fail with INVALID_LINK error')
37+
}
38+
}
39+
}
40+
41+
t.comment(`calling "${method}" with invalid link param throws an error`)
42+
await testOp()
43+
t.comment(`"${method}" can be called again (sidecar not crashed)`)
44+
await testOp()
45+
}
46+
})

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function runTests() {
2121
await import('./12-assets.test.js')
2222
await import('./13-stage.test.js')
2323
await import('./14-preflight.test.js')
24+
await import('./15-opstream.test.js')
2425

2526
test.resume()
2627
}

0 commit comments

Comments
 (0)