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

chore: improve some error messages #3775

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,14 @@ def visit_ImplementsDecl(self, node):
type_ = type_from_annotation(node.annotation)

if not isinstance(type_, InterfaceT):
raise StructureException("not an interface!", node.annotation)
msg = "Not an interface!"
hint = None
if isinstance(type_, ModuleT):
path = type_._module.path
msg += " (Since vyper v0.4.0, interface files are required"
msg += " to have a .vyi suffix.)"
hint = f"try renaming `{path}` to `{path}i`"
raise StructureException(msg, node.annotation, hint=hint)

type_.validate_implements(node)

Expand Down Expand Up @@ -627,6 +634,9 @@ def _load_import(self, node: vy_ast.VyperNode, level: int, module_str: str, alia
def _load_import_helper(
self, node: vy_ast.VyperNode, level: int, module_str: str, alias: str
) -> Any:
if module_str.startswith("vyper.interfaces"):
hint = "try renaming `vyper.interfaces` to `ethereum.ercs`"
raise ModuleNotFound(module_str, hint=hint)
if _is_builtin(module_str):
return _load_builtin_import(level, module_str)

Expand Down Expand Up @@ -724,7 +734,7 @@ def _is_builtin(module_str):

def _load_builtin_import(level: int, module_str: str) -> InterfaceT:
if not _is_builtin(module_str):
raise ModuleNotFoundError(f"Not a builtin: {module_str}") from None
raise ModuleNotFoundError(f"Not a builtin: {module_str}")

builtins_path = vyper.builtins.interfaces.__path__[0]
# hygiene: convert to relpath to avoid leaking user directory info
Expand Down
7 changes: 7 additions & 0 deletions vyper/semantics/types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from vyper import ast as vy_ast
from vyper.exceptions import (
ArrayIndexException,
CompilerPanic,
InstantiationException,
InvalidType,
StructureException,
Expand Down Expand Up @@ -158,6 +159,12 @@ def _type_from_annotation(node: vy_ast.VyperNode) -> VyperType:
# call from_annotation to produce a better error message.
typ_.from_annotation(node)

if hasattr(typ_, "module_t"): # it's a ModuleInfo
typ_ = typ_.module_t

if not isinstance(typ_, VyperType):
raise CompilerPanic("Not a type: {typ_}", node)

return typ_


Expand Down
Loading