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

[Themes] Theme Dev - Do not display warnings when file deletion fails #4426

Merged
merged 4 commits into from
Sep 18, 2024

Conversation

jamesmengo
Copy link
Contributor

@jamesmengo jamesmengo commented Sep 9, 2024

WHY are these changes introduced?

Fixes https://github.com/Shopify/develop-advanced-edits/issues/310

The goals of this task are:
Update the logic so the file system module doesn't attempt to delete a non-existent file.
Change the logging approach from renderWarning to outputDebug since users cannot take any action on this issue.

WHAT is this pull request doing?

- Prevents the watcher from attempting to delete files that don't exist on the local theme

  • outputDebug when the file deletion fails (either due to server error or because the file already doesn't exist)

How to test your changes?

Setup:

  1. Create a theme with missing files -> shopify theme push -d -> delete files from the code editor
  2. Execute shopify-dev theme dev --dev-preview --theme-editor-sync --verbose
  3. Select 'delete files from local theme'
  4. Check for verbose logs. You should see logs like: Failed to delete file "${fileKey}" from remote theme.

BEFORE
image

AFTER

Visual.Studio.Code.-.Dawn.mp4

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@jamesmengo jamesmengo changed the base branch from dev-preview-adjustments to main September 10, 2024 19:31
Copy link
Contributor

github-actions bot commented Sep 10, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 73% 8389/11491
🟡 Branches 69.56% 4091/5881
🟡 Functions 71.75% 2179/3037
🟡 Lines 73.35% 7938/10822
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / ConcurrentOutput.tsx
98.39% (-1.61% 🔻)
90.91% (-4.55% 🔻)
100%
98.33% (-1.67% 🔻)

Test suite run success

1889 tests passing in 857 suites.

Report generated by 🧪jest coverage report action from d9691b8

.then(async (success) => {
if (!success) throw new Error('Unknown issue.')
outputSyncResult('delete', fileKey)
fetchThemeAsset(Number(themeId), fileKey, adminSession)
Copy link
Contributor Author

@jamesmengo jamesmengo Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm debating whether we should make this call explicitly, or just call deleteThemeAsset (which will fail) and handle the failures silently.

This would save an additional call every time a file is deleted, but the tradeoff with that approach would mean that we are unable to discern between legitimate failures of deleteThemeAsset (such as a server failure) from instances where the failure comes from the asset not existing on the remote theme.


Update:
We landed on handling the failures silently rather than adding additional calls to check for file existence on the remote theme

This PR will prevent these calls being made in the first place

@jamesmengo jamesmengo self-assigned this Sep 10, 2024
@jamesmengo jamesmengo added the #gsd:40767 Fortify local development experience for Liquid themes label Sep 10, 2024
@jamesmengo jamesmengo changed the title --wip-- [skip ci] [Themes] Theme Dev - Improve file deletion handling for files that don't exist on remote theme Sep 10, 2024
@jamesmengo jamesmengo marked this pull request as ready for review September 10, 2024 19:51
Copy link
Contributor

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

@jamesmengo jamesmengo changed the title [Themes] Theme Dev - Improve file deletion handling for files that don't exist on remote theme [Themes] Theme Dev - Handle file deletion when file doesn't exist on remote theme Sep 10, 2024
@jamesmengo jamesmengo changed the title [Themes] Theme Dev - Handle file deletion when file doesn't exist on remote theme [Themes] Theme Dev - Do not display warnings when file deletion fails Sep 17, 2024
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for also adding the test!

Comment on lines +507 to +511
const deleteOperationPromise = new Promise<void>((resolve) => {
themeFileSystem.addEventListener('unlink', () => {
setImmediate(resolve)
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI there's also vi.waitFor in Vitest to deal with async code, but I think the promise here is actually better 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#gsd:40767 Fortify local development experience for Liquid themes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants