Skip to content

Commit 718818b

Browse files
committed
refactor(files): early returns in the path resolver
1 parent 75260d5 commit 718818b

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

‎apps/sim/lib/workspace-files/application/file-context.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,16 @@ function requireWorkspaceFileContext<C extends ActiveWorkspaceFileContext>(
9393
*/
9494
async function resolveFileId(input: WorkspaceFileContextInput): Promise<string> {
9595
if (!input.acceptVfsPath || !isWorkspaceFileVfsPath(input.fileId)) return input.fileId
96-
const file =
97-
input.assertedWorkspaceId === undefined
98-
? null
99-
: await resolveFileReference(
100-
{ entityType: 'workspace', entityId: input.assertedWorkspaceId },
101-
input.fileId
102-
).catch((error: unknown) => {
103-
if (error instanceof OrchestrationError && error.code === 'conflict') return null
104-
throw error
105-
})
106-
if (!file) throw new OrchestrationError('not_found', 'File not found')
96+
const notFound = new OrchestrationError('not_found', 'File not found')
97+
if (input.assertedWorkspaceId === undefined) throw notFound
98+
const file = await resolveFileReference(
99+
{ entityType: 'workspace', entityId: input.assertedWorkspaceId },
100+
input.fileId
101+
).catch((error: unknown) => {
102+
if (error instanceof OrchestrationError && error.code === 'conflict') return null
103+
throw error
104+
})
105+
if (!file) throw notFound
107106
return file.id
108107
}
109108

0 commit comments

Comments
 (0)