From 7602904426babcbbff1bff364e8e5c08142cf58a Mon Sep 17 00:00:00 2001 From: Winter-Soren Date: Sun, 9 Feb 2025 18:04:40 +0530 Subject: [PATCH 1/5] fix: handle ipfs.files.stat RPC error responses --- src/bundles/files/actions.js | 43 +++++++++++++++++++++--------------- src/bundles/notify.js | 11 +++++++++ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/bundles/files/actions.js b/src/bundles/files/actions.js index d3f349a33..ff3f0ad78 100644 --- a/src/bundles/files/actions.js +++ b/src/bundles/files/actions.js @@ -101,20 +101,27 @@ 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 + } + }) } } @@ -123,9 +130,9 @@ const stat = async (ipfs, cidOrPath) => { * @param {IPFSService} ipfs * @returns {AsyncIterable} */ -const getRawPins = async function * (ipfs) { - yield * ipfs.pin.ls({ type: 'recursive' }) - yield * ipfs.pin.ls({ type: 'direct' }) +const getRawPins = async function* (ipfs) { + yield* ipfs.pin.ls({ type: 'recursive' }) + yield* ipfs.pin.ls({ type: 'direct' }) } /** @@ -246,7 +253,7 @@ const actions = () => ({ * @param {FileStream[]} source * @param {string} root */ - doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function * (ipfs, { store }) { + doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function* (ipfs, { store }) { const files = source // Skip ignored files .filter($ => !IGNORED_FILES.includes(basename($.path))) @@ -335,7 +342,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 diff --git a/src/bundles/notify.js b/src/bundles/notify.js index 7bd7ca256..f0ba78807 100644 --- a/src/bundles/notify.js +++ b/src/bundles/notify.js @@ -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, From 150663f00ed31ea8c9f08c5f95aa220dd6a05ca1 Mon Sep 17 00:00:00 2001 From: Winter-Soren Date: Sun, 9 Feb 2025 18:27:14 +0530 Subject: [PATCH 2/5] style: fix eslint spacing issues --- src/bundles/files/actions.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bundles/files/actions.js b/src/bundles/files/actions.js index ff3f0ad78..8289ae1fb 100644 --- a/src/bundles/files/actions.js +++ b/src/bundles/files/actions.js @@ -130,9 +130,9 @@ const stat = async (ipfs, cidOrPath) => { * @param {IPFSService} ipfs * @returns {AsyncIterable} */ -const getRawPins = async function* (ipfs) { - yield* ipfs.pin.ls({ type: 'recursive' }) - yield* ipfs.pin.ls({ type: 'direct' }) +const getRawPins = async function * (ipfs) { + yield * ipfs.pin.ls({ type: 'recursive' }) + yield * ipfs.pin.ls({ type: 'direct' }) } /** @@ -253,7 +253,7 @@ const actions = () => ({ * @param {FileStream[]} source * @param {string} root */ - doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function* (ipfs, { store }) { + doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function * (ipfs, { store }) { const files = source // Skip ignored files .filter($ => !IGNORED_FILES.includes(basename($.path))) @@ -342,7 +342,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 From 2e8157313e4940e745b2a917d4290cd842c72652 Mon Sep 17 00:00:00 2001 From: Winter-Soren Date: Sun, 9 Feb 2025 18:38:00 +0530 Subject: [PATCH 3/5] style: remove unnecessary padding in catch block --- src/bundles/files/actions.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/bundles/files/actions.js b/src/bundles/files/actions.js index 8289ae1fb..c19fb3792 100644 --- a/src/bundles/files/actions.js +++ b/src/bundles/files/actions.js @@ -110,7 +110,6 @@ const stat = async (ipfs, cidOrPath) => { return { path, ...stats } } catch (error) { - const e = error instanceof Error ? error : new Error('Unknown error') throw Object.assign(e, { code: 'ERR_FILES_STAT_FAILED', @@ -130,9 +129,9 @@ const stat = async (ipfs, cidOrPath) => { * @param {IPFSService} ipfs * @returns {AsyncIterable} */ -const getRawPins = async function * (ipfs) { - yield * ipfs.pin.ls({ type: 'recursive' }) - yield * ipfs.pin.ls({ type: 'direct' }) +const getRawPins = async function* (ipfs) { + yield* ipfs.pin.ls({ type: 'recursive' }) + yield* ipfs.pin.ls({ type: 'direct' }) } /** @@ -253,7 +252,7 @@ const actions = () => ({ * @param {FileStream[]} source * @param {string} root */ - doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function * (ipfs, { store }) { + doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function* (ipfs, { store }) { const files = source // Skip ignored files .filter($ => !IGNORED_FILES.includes(basename($.path))) @@ -342,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 From ec6cc9783f6c88ada31e6edd0b265edba0c20050 Mon Sep 17 00:00:00 2001 From: Winter-Soren Date: Sun, 9 Feb 2025 19:00:12 +0530 Subject: [PATCH 4/5] style: fix eslint spacing issues --- src/bundles/files/actions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bundles/files/actions.js b/src/bundles/files/actions.js index c19fb3792..cd3a4332c 100644 --- a/src/bundles/files/actions.js +++ b/src/bundles/files/actions.js @@ -129,9 +129,9 @@ const stat = async (ipfs, cidOrPath) => { * @param {IPFSService} ipfs * @returns {AsyncIterable} */ -const getRawPins = async function* (ipfs) { - yield* ipfs.pin.ls({ type: 'recursive' }) - yield* ipfs.pin.ls({ type: 'direct' }) +const getRawPins = async function * (ipfs) { + yield * ipfs.pin.ls({ type: 'recursive' }) + yield * ipfs.pin.ls({ type: 'direct' }) } /** @@ -252,7 +252,7 @@ const actions = () => ({ * @param {FileStream[]} source * @param {string} root */ - doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function* (ipfs, { store }) { + doFilesWrite: (source, root) => spawn(ACTIONS.WRITE, async function * (ipfs, { store }) { const files = source // Skip ignored files .filter($ => !IGNORED_FILES.includes(basename($.path))) From 91930c841283560802e70d759b5eb472f29b5308 Mon Sep 17 00:00:00 2001 From: Soham Bhoir <81645360+Winter-Soren@users.noreply.github.com> Date: Thu, 20 Mar 2025 22:58:29 +0530 Subject: [PATCH 5/5] Update src/bundles/files/actions.js Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> --- src/bundles/files/actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundles/files/actions.js b/src/bundles/files/actions.js index cd3a4332c..e79ffb900 100644 --- a/src/bundles/files/actions.js +++ b/src/bundles/files/actions.js @@ -341,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