Skip to content

Improve error message if an import cannot be found #1307

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
merged 3 commits into from
May 29, 2020
Merged

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented May 28, 2020

This PR fixes #1282 by adding the paths searched to the error message when an imported file cannot be found, for example when trying to import a file by erroneously specifying a file extension, looking like:

ERROR: Import 'tests/compiler/404.ts' not found.
  No such file 'path\to\tests\compiler\404.ts.ts'
  No such file 'path\to\tests\compiler\404.ts\index.ts'
  No such file 'path\to\tests\compiler\404.ts.d.ts'

Doesn't implement a .ts specific error message because that might be intended, but the problem should be clear from the paths searched. cc @torch2424

Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Oh yay! Thanks for fixing this! 😄

I know we recently added a flag so you can specify a file extension other than .ts. Would this be affected by that? Would it be easy to account for that flag here? 🤔

@dcodeIO
Copy link
Member Author

dcodeIO commented May 28, 2020

Oh, right, good catch. Will fix :)

@dcodeIO
Copy link
Member Author

dcodeIO commented May 29, 2020

Now the error looks like

ERROR: Import path 'assembly/404.as' in 'assembly/index' not found.
  No such file 'path\to\assembly\404.as.as'
  No such file 'path\to\assembly\404.as\index.as'
  No such file 'path\to\assembly\404.as.d.as'

on

import "./404.as";

using --extension .as.

@dcodeIO
Copy link
Member Author

dcodeIO commented May 29, 2020

Last commit goes a little further by moving the error reporting for files not being found to the compiler, by accepting a null text in parseFile. Has the advantage that the respective code region can be highlighted in a diagnostic, which is something I always wanted to do. A typical error now looks like ERROR TS6054: File '404.ts.ts' not found.. Doesn't display search paths, but by highlighting the code location this should actually be even clearer.

Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Implementation LGTM 😄 But, I don't know the compiler super well, but from what I do understand, the code makes sense and looks good 😄

@dcodeIO dcodeIO merged commit f93a262 into master May 29, 2020
@dcodeIO dcodeIO deleted the asc-not-found branch June 11, 2020 17:17
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.

AssemblyScript 0.10.0 : Imports that specify a file extension no longer work
2 participants