From 9c3d942e0d8e35a9e5f7090af643b9c638d24c02 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Wed, 15 May 2024 10:52:09 -0500 Subject: [PATCH] refactor: add catch in case of failure Co-authored-by: Jacob Gillespie --- src/utils/mounts.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/utils/mounts.ts b/src/utils/mounts.ts index 1257f29..6d70969 100644 --- a/src/utils/mounts.ts +++ b/src/utils/mounts.ts @@ -248,18 +248,23 @@ interface FileSystems { // Returns the paths of all overlayfs mounts that are children of the given path. // This is useful to unmount all child mounts before unmounting the parent. export async function findOverlayPaths(path: string): Promise { - const {stdout} = await execa('findmnt', ['-R', '-J', path]) - const fs: FileSystems = JSON.parse(stdout) - if (fs.filesystems.length === 0) { - return [] - } + try { + const {stdout} = await execa('findmnt', ['-R', '-J', path]) + const fs: FileSystems = JSON.parse(stdout) + if (fs.filesystems.length === 0) { + return [] + } - const childTargets = new Set() - fs.filesystems.forEach((f) => { - if (f.children) { - f.children.forEach((c) => childTargets.add(c.target)) + const childTargets = new Set() + for (const f of fs.filesystems) { + for (const c of f.children ?? []) { + childTargets.add(c.target) + } } - }) - return Array.from(childTargets) + return Array.from(childTargets) + } catch (err) { + console.error('Failed to run findmnt', err) + return [] + } }