Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle ipfs.files.stat RPC error responses #2327

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
34 changes: 20 additions & 14 deletions src/bundles/files/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,26 @@ const stat = async (ipfs, cidOrPath) => {
} else {
stats = await ipfs.files.stat(path)
}
return { path, ...stats }
} catch (e) {
// Discard error and mark DAG as 'unknown' to unblock listing other pins.
// Clicking on 'unknown' entry will open it in Inspector.
// No information is lost: if there is an error related
// to specified hashOrPath user will read it in Inspector.
const [, , cid] = path.split('/')
return {
path: hashOrPath,
cid: CID.asCID(cid) ?? CID.parse(cid),
type: 'unknown',
cumulativeSize: 0,
size: 0

if (stats.type === 'error') {
throw Object.assign(new Error(stats.message || 'Failed to get file stats'), {
code: 'ERR_FILES_STAT_FAILED'
})
}

return { path, ...stats }
} catch (error) {
const e = error instanceof Error ? error : new Error('Unknown error')
throw Object.assign(e, {
code: 'ERR_FILES_STAT_FAILED',
fallback: {
path: hashOrPath,
cid: CID.asCID(path.split('/')[2]) ?? CID.parse(path.split('/')[2]),
type: 'unknown',
cumulativeSize: 0,
size: 0
}
})
}
}

Expand Down Expand Up @@ -335,7 +341,7 @@ const actions = () => ({
* same file) to crash webui, nor want to bother user with false-negatives
* @param {Function} fn
*/
const tryAsync = async fn => { try { await fn() } catch (_) {} }
const tryAsync = async fn => { try { await fn() } catch (_) { } }

try {
// try removing from MFS first
Expand Down
11 changes: 11 additions & 0 deletions src/bundles/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ const notify = {
return { ...state, show: false }
}

if (action.type === 'FILES_STAT_FAILED') {
return {
...state,
show: true,
error: true,
eventId: 'FILES_EVENT_FAILED',
code: action.payload.error.code,
msgArgs: { message: action.payload.error.message }
}
}

if (action.type === 'STATS_FETCH_FAILED') {
return {
...state,
Expand Down