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

Fix: Template Literal Syntax in Error Handling for Asset File Paths in Metro #1265

Open
fredrikburmester opened this issue Apr 30, 2024 · 2 comments

Comments

@fredrikburmester
Copy link
Contributor

Hi! 👋

Today, I used patch-package to patch metro@0.80.6 for the project I'm working on.

While working, I noticed an issue with asset file path error handling in metro. The error message was not formatting the file path correctly, making debugging more difficult. To resolve this, I applied a small patch that corrects the template literal syntax for error messages.

Here is the diff that solved my problem:

diff --git a/node_modules/metro/src/node-haste/lib/AssetPaths.js b/node_modules/metro/src/node-haste/lib/AssetPaths.js
index 7d44292..4a2577a 100644
--- a/node_modules/metro/src/node-haste/lib/AssetPaths.js
+++ b/node_modules/metro/src/node-haste/lib/AssetPaths.js
@@ -41,7 +41,7 @@ function tryParse(filePath, platforms) {
 function parse(filePath, platforms) {
   const result = tryParse(filePath, platforms);
   if (result == null) {
-    throw new Error("invalid asset file path: `${filePath}");
+    throw new Error(`invalid asset file path: ${filePath}`);
   }
   return result;
 }

This change ensures that the error message correctly includes the file path, aiding in troubleshooting and enhancing the developer experience. I believe this might be beneficial for others facing similar issues.

@robhogan
Copy link
Contributor

Hi, thanks! That looks good to me - would you like to submit a PR?

@fredrikburmester
Copy link
Contributor Author

@robhogan I submitted a PR here.

facebook-github-bot pushed a commit that referenced this issue May 1, 2024
…1267)

Summary:
This is a PR that solves [issue 1265](#1265).

This pull request corrects a syntax error in the template literal used for handling error messages regarding asset file paths within Metro. The existing implementation failed to properly format the file path in the error message. This change updates the syntax to correctly embed the file path variable into the error message.

Changelog: [Fix] Correct template literal syntax in error handling for asset file paths.

Pull Request resolved: #1267

Test Plan:
To verify the correction, I conducted the following steps:

1. Triggered the error handling code with an incorrect asset file path to ensure the error message **includes the intended file path**.
2. Reviewed the output to confirm the file path is now **correctly formatted** within the error message.

Reviewed By: huntie

Differential Revision: D56811594

Pulled By: robhogan

fbshipit-source-id: f089996659222bca3cd0896ae13292ebb4747428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants