Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locales/en/notify.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ipfsPinFailReason": "Unable to set pinning at {serviceName}: {errorMsg}",
"ipfsPinSucceedReason": "Successfully pinned at {serviceName}",
"ipfsUnpinSucceedReason": "Successfully unpinned from {serviceName}",
"ipnsPublishFailReason": "Unable to publish to IPNS under key {keyName}: {errorMsg}",
"ipfsIsBack": "Normal IPFS service has resumed. Enjoy!",
"folderExists": "An item with that name already exists. Please choose another.",
"filesFetchFailed": "Failed to get those files. Please check the path and try again.",
Expand Down
13 changes: 11 additions & 2 deletions src/bundles/ipns.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,18 @@ const ipnsBundle = {
store.doFetchIpnsKeys()
},

doPublishIpnsKey: (cid, key) => async ({ getIpfs, store }) => {
doPublishIpnsKey: (cid, key) => async ({ getIpfs, dispatch }) => {
const ipfs = getIpfs()
await ipfs.name.publish(cid, { key })

try {
await ipfs.name.publish(cid, { key })
} catch (err) {
// Surface the RPC failure as a toast and re-throw so the publish modal
// leaves its progress state instead of hanging on a finished-looking bar.
console.error(`unexpected error publishing IPNS record for ${cid} (key: ${key})`, err)
dispatch({ type: 'IPNS_PUBLISH_FAILED', msgArgs: { keyName: key, errorMsg: err.toString() } })
throw err
}

// Trigger background provide operation for the published CID
dispatchAsyncProvide(cid, ipfs, 'IPNS')
Expand Down
13 changes: 13 additions & 0 deletions src/bundles/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ const notify = {
}
}

if (action.type === 'IPNS_PUBLISH_FAILED') {
return {
...state,
show: true,
error: true,
msgArgs: action.msgArgs,
eventId: action.type
}
}

if (action.type === 'IPFS_CONNECT_FAILED') {
return {
...state,
Expand Down Expand Up @@ -159,6 +169,9 @@ const notify = {
if (eventId === 'IPFS_UNPIN_SUCCEED') {
return 'ipfsUnpinSucceedReason'
}
if (eventId === 'IPNS_PUBLISH_FAILED') {
return 'ipnsPublishFailReason'
}

if (eventId === 'FILES_EVENT_FAILED') {
const type = code ? code.replace(/^(ERR_)/, '') : ''
Expand Down
14 changes: 14 additions & 0 deletions src/bundles/notify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,17 @@ it('should notify about file errors', async () => {
expect(store.selectNotifyI18nKey()).toEqual('filesEventFailed')
store.dispatch({ type: 'FILES_WRITE_FINISHED' })
})

it('should notify about IPNS publish errors with the original message', async () => {
const store = composeBundlesRaw(
appTimeBundle,
ipfsBundle(),
notifyBundle
)()
expect(store.selectNotify().show).toEqual(false)
store.dispatch({ type: 'IPNS_PUBLISH_FAILED', msgArgs: { keyName: 'self', errorMsg: 'Error: Internal Server Error' } })
expect(store.selectNotify().show).toEqual(true)
expect(store.selectNotify().error).toEqual(true)
expect(store.selectNotify().msgArgs).toEqual({ keyName: 'self', errorMsg: 'Error: Internal Server Error' })
expect(store.selectNotifyI18nKey()).toEqual('ipnsPublishFailReason')
})
3 changes: 3 additions & 0 deletions src/files/modals/publish-modal/PublishModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const PublishModal = ({ t, tReady, onLeave, onSubmit, file, ipnsKeys, pub
try {
const startTs = new Date().getTime()
setStart(startTs)
setError(null)

await onSubmit(selectedKey.name)
setLink(`${publicGateway}/ipns/${selectedKey.id}`)
Expand All @@ -53,6 +54,8 @@ export const PublishModal = ({ t, tReady, onLeave, onSubmit, file, ipnsKeys, pub
const endTs = new Date().getTime()
doUpdateExpectedPublishTime((endTs - startTs) / 1000)
} catch (err) {
// Leave the progress state so the error renders and Publish re-enables for a retry.
setStart(null)
setError(err)
}
}
Expand Down
Loading