Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[AssetMapper] Fixing bug where a circular exception could be thrown while making error message #51345

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

Merged

Conversation

weaverryan
Copy link
Member

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? none
Tickets Fix #51291
License MIT
Doc PR Not needed

AssetMapper's JavaScriptImportPathCompiler parses import statements. That process is imperfect and will over-match in some cases (e.g. matching import() that is commented-out). but that's not a huge issue: any matches are simply added to the importmap and matches for not-found-files are ignored.

However, in #51291, we hit a spot where, while trying to improve the log message (Try adding ".js" to the end of the import - i.e. "%s.js"), we triggered a circular exception. This PR suppresses that.

We may need to improve the parsing logic later to handle more edge-cases, but we'll handle those if/when they come up.

Cheers!

}
});

$asset = new MappedAsset('html.js', '/path/to/app.js');
Copy link

Choose a reason for hiding this comment

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

I think there's a typo here, shouldn't it be 'htmx.js'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup - it doesn't matter for the test, but definitely wasn't my intention. Fixing it - thanks :)

Copy link
Member

Choose a reason for hiding this comment

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

Well, with html.js, the test would not trigger a circular error, and so would not prevent regressions. So it definitely matters.

Copy link
Member Author

Choose a reason for hiding this comment

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

No - the circular reference is triggered a bit manually on the mock. So you're correct in a real-world example, but in this case, this part doesn't matter (creating a test that resulted in a natural, real-world circular reference was going to be a lot more work as we need a real AssetMapper, MappedAssetFactory, etc.

@nicolas-grekas
Copy link
Member

Thank you @weaverryan.

@nicolas-grekas nicolas-grekas force-pushed the asset-mapper-avoid-circular-on-error branch from a9305a9 to 63b9635 Compare August 14, 2023 14:11
@nicolas-grekas nicolas-grekas merged commit aba725f into symfony:6.3 Aug 14, 2023
@weaverryan weaverryan deleted the asset-mapper-avoid-circular-on-error branch August 15, 2023 11:01
@fabpot fabpot mentioned this pull request Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants