Skip to content

Commit 2dc4fa1

Browse files
committed
fixup! preserve error reported on failure
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
1 parent 914800c commit 2dc4fa1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/miner-info.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ import { RPC_URL, RPC_AUTH } from './constants.js'
33

44
/**
55
* @param {string} minerId A miner actor id, e.g. `f0142637`
6+
* @param {object} options
7+
* @param {number} [options.maxAttempts]
68
* @returns {Promise<string>} Miner's PeerId, e.g. `12D3KooWMsPmAA65yHAHgbxgh7CPkEctJHZMeM3rAvoW8CZKxtpG`
79
*/
8-
export async function getMinerPeerId (minerId) {
10+
export async function getMinerPeerId (minerId, { maxAttempts = 5 } = {}) {
911
try {
1012
const res = await retry(() => rpc('Filecoin.StateMinerInfo', minerId, null), {
1113
// The maximum amount of attempts until failure.
12-
maxAttempts: 5,
14+
maxAttempts,
1315
// The initial and minimum amount of milliseconds between attempts.
1416
minTimeout: 5_000,
1517
// How much to backoff after each retry.
1618
multiplier: 1.5
1719
})
1820
return res.PeerId
1921
} catch (err) {
22+
if (err.name === 'RetryError' && err.cause) {
23+
// eslint-disable-next-line no-ex-assign
24+
err = err.cause
25+
}
2026
err.message = `Cannot obtain miner info for ${minerId}: ${err.message}`
2127
throw err
2228
}

test/miner-info.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('get peer id of a known miner', async () => {
1111

1212
test('get peer id of a miner that does not exist', async () => {
1313
try {
14-
const result = await getMinerPeerId('f010')
14+
const result = await getMinerPeerId('f010', { maxAttempts: 1 })
1515
throw new AssertionError(
1616
`Expected "getMinerPeerId()" to fail, but it resolved with "${result}" instead.`
1717
)

0 commit comments

Comments
 (0)