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

Improve compilation job error messages #989

Merged
merged 7 commits into from Nov 27, 2020
Merged

Conversation

fvictorio
Copy link
Member

This PR improves the errors shown when the files can't be compiled.

@@ -981,13 +972,11 @@ subtask(TASK_COMPILE_SOLIDITY_HANDLE_COMPILATION_JOBS_FAILURES)
{
compilationJobsCreationErrors,
}: {
compilationJobsCreationErrors: CompilationJobsCreationErrors;
compilationJobsCreationErrors: CompilationJobCreationError[];
},
{ run }
) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This function is huge. I think we should move it to another module, but I didn't do it yet so that the PR it's easier to review.

Also, there's a lot of duplication here, especially between the "invalid imports" and the "invalid indirect imports" parts. Maybe we can abstract that, but I'm inclined to leave this as straightforward as possible.

reason: CompilationJobCreationErrorReason;
file: ResolvedFile;
extra?: any;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main type change. The CompilationJobsCreationError type, that was a map from an error tipe to a list of source names with that error, is gone. Instead I used a list of errors. Each error has a reason (this is the extendable enum previously called CompilationJobCreationError), a file, and an optional "extra" type, that can have more information about the error.

I don't love having an any for the extra field, but I'm not sure it's worth it to do something trickier here.

import {
CompilationJobCreationError,
CompilationJobCreationErrorReason,
} from "../../../src/types/builtin-tasks";
Copy link
Member Author

Choose a reason for hiding this comment

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

This file needs more tests, but I will add them after the new types are definitive.

if (incompatibleImports.length === 1) {
importsText = ` imports ${incompatibleImports[0]}`;
} else if (incompatibleImports.length === 2) {
importsText = ` imports ${incompatibleImports[0]} and ${incompatibleImports[1]}`;
Copy link
Member

Choose a reason for hiding this comment

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

Are these direct imports?

Copy link
Member

Choose a reason for hiding this comment

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

ah, yes. They are. Maybe add a "direct" to the var names?

);

log(
`File ${sourceName} depends on files ${incompatibleImportsFiles
Copy link
Member

Choose a reason for hiding this comment

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

We could add the entire import path here, can't we?

Something like a second line with "Import path: A.sol > B.sol > Incompatible.sol"


`;
}

reasons += `Learn more about compiler configuration at https://hardhat.org/config
errorMessage += `Learn more about compiler configuration at https://hardhat.org/config
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
errorMessage += `Learn more about compiler configuration at https://hardhat.org/config
errorMessage += `This can happen because they have incompatible Solidity pragmas, or don't match any of your configured Solidity compilers. Learn more about compiler configuration at https://hardhat.org/config

Copy link
Member Author

Choose a reason for hiding this comment

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

Couldn't that message be misleading? If there are no matching compilers or if there are incompatible imports, we should have detected it and reported it as a different error reason.

Copy link
Member

Choose a reason for hiding this comment

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

I believe this error has two reasons:

  • The range described by the concatenation of all the pragmas is empty.
  • The range described by the concatenation of all the pragmas doesn't include any of the configured compilers, even though each individual pragma does match at least one of the compilers.

Is that right?

If so, we should aim to explain that without too many details.

@alcuadrado alcuadrado merged commit 7b80092 into master Nov 27, 2020
@alcuadrado alcuadrado deleted the better-compilation-errors branch November 27, 2020 20:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants