diff --git a/packages/theme/src/cli/utilities/errors.ts b/packages/theme/src/cli/utilities/errors.ts index b6ee5c89e4..8b3f4c1975 100644 --- a/packages/theme/src/cli/utilities/errors.ts +++ b/packages/theme/src/cli/utilities/errors.ts @@ -23,15 +23,13 @@ export function renderThrownError(headline: string, error: Error | AbortError) { * @param preset - The type of operation that failed. * @returns A function that accepts an error and renders it. */ -export function createRenderCatchError(resource: string, preset?: 'delete' | 'upload') { - let headline = resource - - if (preset) { - headline = - preset === 'delete' - ? `Failed to delete file "${resource}" from remote theme.` - : `Failed to upload file "${resource}" to remote theme.` - } +export function createSyncingCatchError(resource: string, preset?: 'delete' | 'upload') { + const headline = + { + delete: `Failed to delete file "${resource}" from remote theme.`, + upload: `Failed to upload file "${resource}" to remote theme.`, + default: resource, + }[preset ?? 'default'] ?? resource return (error: Error) => { renderThrownError(headline, error) diff --git a/packages/theme/src/cli/utilities/theme-fs.ts b/packages/theme/src/cli/utilities/theme-fs.ts index cec3d5e89e..f08cb26f0d 100644 --- a/packages/theme/src/cli/utilities/theme-fs.ts +++ b/packages/theme/src/cli/utilities/theme-fs.ts @@ -5,7 +5,7 @@ import { getPatternsFromShopifyIgnore, } from './asset-ignore.js' import {Notifier} from './notifier.js' -import {createRenderCatchError} from './errors.js' +import {createSyncingCatchError} from './errors.js' import {DEFAULT_IGNORE_PATTERNS, timestampDateFormat} from '../constants.js' import {glob, readFile, ReadOptions, fileExists, mkdir, writeFile, removeFile} from '@shopify/cli-kit/node/fs' import {joinPath, basename, relativePath} from '@shopify/cli-kit/node/path' @@ -163,7 +163,7 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti return true }) - .catch(createRenderCatchError(fileKey, 'upload')) + .catch(createSyncingCatchError(fileKey, 'upload')) emitEvent(eventName, { fileKey, @@ -200,7 +200,7 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti unsyncedFileKeys.delete(fileKey) outputSyncResult('delete', fileKey) }) - .catch(createRenderCatchError(fileKey, 'delete')) + .catch(createSyncingCatchError(fileKey, 'delete')) } const directoriesToWatch = new Set( diff --git a/packages/theme/src/cli/utilities/theme-uploader.ts b/packages/theme/src/cli/utilities/theme-uploader.ts index f521ee4bb9..c81c396bee 100644 --- a/packages/theme/src/cli/utilities/theme-uploader.ts +++ b/packages/theme/src/cli/utilities/theme-uploader.ts @@ -1,7 +1,7 @@ import {partitionThemeFiles} from './theme-fs.js' import {rejectGeneratedStaticAssets} from './asset-checksum.js' import {renderTasksToStdErr} from './theme-ui.js' -import {createRenderCatchError} from './errors.js' +import {createSyncingCatchError} from './errors.js' import {AdminSession} from '@shopify/cli-kit/node/session' import {Result, Checksum, Theme, ThemeFileSystem} from '@shopify/cli-kit/node/themes/types' import {AssetParams, bulkUploadThemeAssets, deleteThemeAsset} from '@shopify/cli-kit/node/themes/api' @@ -139,7 +139,7 @@ function buildDeleteJob( .catch((error: Error) => { failedDeleteAttempts++ if (failedDeleteAttempts > 3) throw error - createRenderCatchError(file.key, 'delete')(error) + createSyncingCatchError(file.key, 'delete')(error) }) .finally(() => { progress.current++