Skip to content

Import Error Handling #1394

@CruzMolina

Description

@CruzMolina

What's your issue about?

Currently vyper does not provide meaningful errors when incorrectly attempting imports.

When attempting to compile an incorrect relative import, such as:

# myContract.vy

# foobar.vy does not exist or is named foo_bar.vy
import foobar as FooBar

stored_data: uint256

@public
def set(new_value : uint256):
    self.stored_data = new_value

@public
@constant
def get() -> uint256:
    return self.stored_data

Calling vyper myContract.vy returns:

IndexError: tuple index out of range

How can it be fixed?

When comparing the behavior of vyper to solc, given a contract such as:

// myContract.sol
pragma solidity >=0.4.0 <0.7.0;

// foobar.sol doesn't exist or was renamed to foo_bar.sol
import "./foobar.sol";

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

Calling solc myContract.sol returns:

myContract.sol:5:1: Error: Source "foobar.sol" not found: File outside of allowed directories.
import "./foobar.sol";
^--------------------^

Conversely, calling solc myContract.sol --allow-paths . returns:

myContract.sol:5:1: Error: Source "foobar.sol" not found: File not found.
import "./foobar.sol";
^--------------------^

I imagine something in a similar vein would be a useful feature for vyper to have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug that shouldn't change language semantics when fixed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions