ape icon indicating copy to clipboard operation
ape copied to clipboard

feat: error msg to say missing compiler

Open Ninjagod1251 opened this issue 2 years ago • 4 comments

Overview

Provide a simple overview of what you wish to see added. Please include: Currently when you don't have the right compiler installed and you try and run ape test

you get this error

__________________________________________________ ERROR at setup of test_mint ___________________________________________________

owner = <TestAccount 0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C>
project = <ape.managers.project.manager.ProjectManager object at 0x7f9b4f5c1760>

    @pytest.fixture(scope="session")
    def token(owner, project):
>       return owner.deploy(project.Token)
E       AttributeError: 'ProjectManager' object has no attribute 'Token'

tests/conftest.py:14: AttributeError
======================================================== warnings summary ========================================================
../../virtualenvs/ape/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191
  /home/chris/virtualenvs/ape/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
==================================================== short test summary info =====================================================
ERROR tests/test_token.py::test_initial_state - AttributeError: 'ProjectManager' object has no attribute 'Token'
ERROR tests/test_token.py::test_transfer - AttributeError: 'ProjectManager' object has no attribute 'Token'
ERROR tests/test_token.py::test_transfer_from - AttributeError: 'ProjectManager' object has no attribute 'Token'
ERROR tests/test_token.py::test_approve - AttributeError: 'ProjectManager' object has no attribute 'Token'
ERROR tests/test_token.py::test_mint - AttributeError: 'ProjectManager' object has no attribute 'Token'
============================================ 1 skipped, 1 warning, 5 errors in 0.55s =============================================
(ape) chris@DESKTOP-ID4V0R6 ~/demo/erc20Project $ 

I would like to fix the error msg and have it say you might a compiler missing?

Ninjagod1251 avatar Aug 10 '22 23:08 Ninjagod1251

@fubuloubu @unparalleled-js

What is a good way for us to make it easier to understand this issue?

Ninjagod1251 avatar Aug 10 '22 23:08 Ninjagod1251

@dtdang we ran into this issue and some of our user did too

Ninjagod1251 avatar Aug 10 '22 23:08 Ninjagod1251

What is a good way for us to make it easier to understand this issue?

In project manager getattr, if we cant find the contract container, check the contents of the contracts folder for a matching file name. If found, raise a different exception saying "Missing compiler plugin installation for '{ext}' source types."

antazoey avatar Aug 10 '22 23:08 antazoey

What is a good way for us to make it easier to understand this issue?

In project manager getattr, if we cant find the contract container, check the contents of the contracts folder for a matching file name. If found, raise a different exception saying "Missing compiler plugin installation for '{ext}' source types."

Might not work for solidity files, where the file name sometimes doesn't match the types it contains.

Perhaps just adding a simple "make sure that you have the right compiler plugins installed" or even better: search for files in the contracts/ folder and see if there are any extensions without a compiler in this situation (and suggest they install one that can handle that file type).

fubuloubu avatar Aug 11 '22 00:08 fubuloubu

Currently, you can check for missing extensions via:

project.extensions_with_missing_compilers

Then, in ProjectManager.__getattr__(), on line 371 where it says return self.__getattribute__(attr_name) # type: ignore, we can wrap that in a try/except and catch AttributeError and then in except block, handle like this:

try:
    # Fixes anomaly when accessing non-ContractType attributes.
    # Returns normal attribute if exists. Raises 'AttributeError' otherwise.
    return self.__getattribute__(attr_name)  # type: ignore
except AttributeError as err:
    message = f"ProjectManager has no attribute or contract named '{attr_name}'.
    missing_exts = self.compilers_with_missing_ext
    if missing_exts:
        message = f"{message}. Could it be from one of the missing compilers for extensions: {', '.join(missing_exts)}"
    
    raise AttributeError(message) from err

antazoey avatar Sep 27 '22 18:09 antazoey

note: project.extensions_with_missing_compilers must be fed an extension, a list of extensions, or an empty list as an argument like this: project.extensions_with_missing_compilers([])

sabotagebeats avatar Sep 29 '22 17:09 sabotagebeats

note: project.extensions_with_missing_compilers must be fed an extension, a list of extensions, or an empty list as an argument like this: project.extensions_with_missing_compilers([])

refactored this to not require an argument in #1087

sabotagebeats avatar Sep 29 '22 18:09 sabotagebeats