Skip to content

Commit

Permalink
feat: exit code 2 when walled failed screening (#450)
Browse files Browse the repository at this point in the history
When the user provides FIL_WALLET_ADDRESS that's rejected by our
screening service, return a different exit code to allow Station Desktop
to detect this error and apply different error handling.

Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
  • Loading branch information
bajtos authored May 10, 2024
1 parent 0d8cb83 commit b5925e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 8 additions & 4 deletions commands/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ const moduleNames = [
'zinnia'
]

const panic = msg => {
/**
* @param {string} msg
* @param {number} [exitCode]
*/
const panic = (msg, exitCode = 1) => {
console.error(msg)
process.exit(1)
process.exit(exitCode)
}

export const station = async ({ json, experimental }) => {
if (!FIL_WALLET_ADDRESS) panic('FIL_WALLET_ADDRESS required')
if (FIL_WALLET_ADDRESS.startsWith('f1')) {
panic('f1 addresses are currently not supported. Please use an f4 or 0x address')
panic('Invalid FIL_WALLET_ADDRESS: f1 addresses are currently not supported. Please use an f4 or 0x address.')
}
if (
!FIL_WALLET_ADDRESS.startsWith('f410') &&
Expand All @@ -48,7 +52,7 @@ export const station = async ({ json, experimental }) => {
console.error('Failed to validate FIL_WALLET_ADDRESS address. Retrying...')
}
)
if (fetchRes.status === 403) panic('Invalid FIL_WALLET_ADDRESS address')
if (fetchRes.status === 403) panic('Invalid FIL_WALLET_ADDRESS address', 2)
if (!fetchRes.ok) panic('Failed to validate FIL_WALLET_ADDRESS address')
const ethAddress = FIL_WALLET_ADDRESS.startsWith('0x')
? FIL_WALLET_ADDRESS
Expand Down
20 changes: 13 additions & 7 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ describe('CLI', () => {
}))
})
it('fails with sanctioned address', async () => {
await assert.rejects(execa(station, {
env: {
STATE_ROOT: getUniqueTempDir(),
PASSPHRASE,
FIL_WALLET_ADDRESS: '0x1da5821544e25c636c1417ba96ade4cf6d2f9b5a'
}
}))
try {
await execa(station, {
env: {
STATE_ROOT: getUniqueTempDir(),
PASSPHRASE,
FIL_WALLET_ADDRESS: '0x1da5821544e25c636c1417ba96ade4cf6d2f9b5a'
}
})
} catch (err) {
assert.strictEqual(err.exitCode, 2)
return
}
assert.fail('Expected Station Core to return a non-zero exit code')
})
it('starts without passphrase in a fresh install', async () => {
const ps = execa(station, {
Expand Down

0 comments on commit b5925e1

Please sign in to comment.