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 incorrect path in error overlay on Win #6679

Merged
merged 1 commit into from Mar 31, 2023
Merged

Fix incorrect path in error overlay on Win #6679

merged 1 commit into from Mar 31, 2023

Conversation

fcFn
Copy link
Contributor

@fcFn fcFn commented Mar 27, 2023

Changes

Fix #6678.

Testing

An e2e test was added.

Docs

This just fixes a bug so no docs changes are needed.

@changeset-bot
Copy link

changeset-bot bot commented Mar 27, 2023

🦋 Changeset detected

Latest commit: 5f41cc5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 27, 2023
@fcFn fcFn marked this pull request as draft March 28, 2023 00:17
@fcFn
Copy link
Contributor Author

fcFn commented Mar 28, 2023

Ah, it seems that the title of the file path element that is shown in the error overlay is supposed to be absolute while the text is supposed to be relative to the project root? That's how it is on Linux.

Well, I fixed the issued with the double path on Windows so that now it at least shows a valid Windows path and the Open in editor button works on Windows (and the tests now pass on both Linux and Windows).

Should I work some more on this and make it show the relative path in the text content like it does on Linux?

@fcFn fcFn marked this pull request as ready for review March 28, 2023 01:20
@Princesseuh
Copy link
Member

Should I work some more on this and make it show the relative path in the text content like it does on Linux?

If you have time, that'd be awesome! We generally aim for parity. But since this is ultimately a minor detail, it's fine either way imo

@fcFn
Copy link
Contributor Author

fcFn commented Mar 28, 2023

Should I work some more on this and make it show the relative path in the text content like it does on Linux?

If you have time, that'd be awesome! We generally aim for parity. But since this is ultimately a minor detail, it's fine either way imo

@Princesseuh That's done! I updated the test so that it will check that the relative path is displayed and the full path is used for opening the editor.

@fcFn
Copy link
Contributor Author

fcFn commented Mar 28, 2023

I just discovered that while fixing the path on Windows when the error is in pages the path will now break if the error is in a component 😅 I will investigate further.

@fcFn fcFn marked this pull request as draft March 28, 2023 17:58
@fcFn fcFn marked this pull request as ready for review March 28, 2023 21:04
@fcFn
Copy link
Contributor Author

fcFn commented Mar 28, 2023

I fixed it and added another test to check the path when the error is in a component.

@@ -636,7 +636,8 @@ class ErrorOverlay extends HTMLElement {
const codeContent = code.querySelector<HTMLDivElement>('#code-content');

if (codeHeader) {
const cleanFile = err.loc.file.split('/').slice(-2).join('/');
const separator = err.loc.file.includes('/') ? '/' : '\\';
Copy link
Contributor Author

@fcFn fcFn Mar 29, 2023

Choose a reason for hiding this comment

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

Account for Windows separators


// Normalize the paths so that we can correctly detect if it's absolute on any platform
const normalizedFile = error.loc?.file?.replace(/\\/g, '/');
const normalizedRootFolder = removeLeadingForwardSlashWindows(rootFolder?.pathname || '');
Copy link
Contributor Author

@fcFn fcFn Mar 29, 2023

Choose a reason for hiding this comment

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

Remove a leading forward slash which rootFolder.pathname comes with which is invalid on Windows (e.g. /C:/) and will always fail the check for the path being absolute below which results in the bug that is described in the issue.

@@ -52,6 +52,28 @@ test.describe('Error display', () => {
expect(await page.locator('vite-error-overlay').count()).toEqual(0);
});

test('shows correct file path when a page has an error', async ({ page, astro }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two different tests because on Windows the path separators are different depending on the location of the error (i.e. component vs page).

@fcFn
Copy link
Contributor Author

fcFn commented Mar 29, 2023

@Princesseuh Thank you for the hint about the path utilities!

I think I found the underlying cause and made the fix more robust. I added a comment for the less clear part and I added more explanations in the comments for the PR as I'm not sure which of those should be added to the code.

@Princesseuh Princesseuh merged commit 08e92f4 into withastro:main Mar 31, 2023
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect path to file in the error overlay on windows
2 participants