mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #12434 from ethereum/outputLocations
Output searched locations on import failure.
This commit is contained in:
commit
5c3bcb6c2d
@ -116,7 +116,6 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _so
|
|||||||
for (auto const& prefix: prefixes)
|
for (auto const& prefix: prefixes)
|
||||||
{
|
{
|
||||||
boost::filesystem::path canonicalPath = normalizeCLIPathForVFS(prefix / strippedSourceUnitName, SymlinkResolution::Enabled);
|
boost::filesystem::path canonicalPath = normalizeCLIPathForVFS(prefix / strippedSourceUnitName, SymlinkResolution::Enabled);
|
||||||
|
|
||||||
if (boost::filesystem::exists(canonicalPath))
|
if (boost::filesystem::exists(canonicalPath))
|
||||||
candidates.push_back(std::move(canonicalPath));
|
candidates.push_back(std::move(canonicalPath));
|
||||||
}
|
}
|
||||||
@ -124,7 +123,12 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _so
|
|||||||
auto pathToQuotedString = [](boost::filesystem::path const& _path){ return "\"" + _path.string() + "\""; };
|
auto pathToQuotedString = [](boost::filesystem::path const& _path){ return "\"" + _path.string() + "\""; };
|
||||||
|
|
||||||
if (candidates.empty())
|
if (candidates.empty())
|
||||||
return ReadCallback::Result{false, "File not found."};
|
return ReadCallback::Result{
|
||||||
|
false,
|
||||||
|
"File not found. Searched the following locations: " +
|
||||||
|
joinHumanReadable(prefixes | ranges::views::transform(pathToQuotedString), ", ") +
|
||||||
|
"."
|
||||||
|
};
|
||||||
|
|
||||||
if (candidates.size() >= 2)
|
if (candidates.size() >= 2)
|
||||||
return ReadCallback::Result{
|
return ReadCallback::Result{
|
||||||
@ -135,11 +139,13 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _so
|
|||||||
"."
|
"."
|
||||||
};
|
};
|
||||||
|
|
||||||
FileSystemPathSet extraAllowedPaths = {m_basePath.empty() ? "." : m_basePath};
|
FileSystemPathSet allowedPaths =
|
||||||
extraAllowedPaths += m_includePaths;
|
m_allowedDirectories +
|
||||||
|
decltype(allowedPaths){m_basePath.empty() ? "." : m_basePath} +
|
||||||
|
m_includePaths;
|
||||||
|
|
||||||
bool isAllowed = false;
|
bool isAllowed = false;
|
||||||
for (boost::filesystem::path const& allowedDir: m_allowedDirectories + extraAllowedPaths)
|
for (boost::filesystem::path const& allowedDir: allowedPaths)
|
||||||
if (isPathPrefix(normalizeCLIPathForVFS(allowedDir, SymlinkResolution::Enabled), candidates[0]))
|
if (isPathPrefix(normalizeCLIPathForVFS(allowedDir, SymlinkResolution::Enabled), candidates[0]))
|
||||||
{
|
{
|
||||||
isAllowed = true;
|
isAllowed = true;
|
||||||
@ -147,7 +153,12 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _so
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isAllowed)
|
if (!isAllowed)
|
||||||
return ReadCallback::Result{false, "File outside of allowed directories."};
|
return ReadCallback::Result{
|
||||||
|
false,
|
||||||
|
"File outside of allowed directories. The following are allowed: " +
|
||||||
|
joinHumanReadable(allowedPaths | ranges::views::transform(pathToQuotedString), ", ") +
|
||||||
|
"."
|
||||||
|
};
|
||||||
|
|
||||||
if (!boost::filesystem::is_regular_file(candidates[0]))
|
if (!boost::filesystem::is_regular_file(candidates[0]))
|
||||||
return ReadCallback::Result{false, "Not a valid file."};
|
return ReadCallback::Result{false, "Not a valid file."};
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"component": "general",
|
"component": "general",
|
||||||
"formattedMessage": "Cannot import url (\"in.yul\"): File not found.",
|
"formattedMessage": "Cannot import url (\"in.yul\"): File not found. Searched the following locations: \"\".",
|
||||||
"message": "Cannot import url (\"in.yul\"): File not found.",
|
"message": "Cannot import url (\"in.yul\"): File not found. Searched the following locations: \"\".",
|
||||||
"severity": "error",
|
"severity": "error",
|
||||||
"type": "IOError"
|
"type": "IOError"
|
||||||
},
|
},
|
||||||
|
@ -100,7 +100,7 @@ ImportCheck checkImport(
|
|||||||
return ImportCheck::OK();
|
return ImportCheck::OK();
|
||||||
|
|
||||||
static regex const sourceNotFoundErrorRegex{
|
static regex const sourceNotFoundErrorRegex{
|
||||||
R"(^Error \(6275\): Source ".+" not found: (.*)\.\n)"
|
R"(^Error \(6275\): Source "[^"]+" not found: (.*)\.\n)"
|
||||||
R"(\s*--> .*<stdin>:\d+:\d+:\n)"
|
R"(\s*--> .*<stdin>:\d+:\d+:\n)"
|
||||||
R"(\s*\|\n)"
|
R"(\s*\|\n)"
|
||||||
R"(\d+\s*\| import '.+';\n)"
|
R"(\d+\s*\| import '.+';\n)"
|
||||||
@ -110,12 +110,12 @@ ImportCheck checkImport(
|
|||||||
smatch submatches;
|
smatch submatches;
|
||||||
if (!regex_match(cliResult.stderrContent, submatches, sourceNotFoundErrorRegex))
|
if (!regex_match(cliResult.stderrContent, submatches, sourceNotFoundErrorRegex))
|
||||||
return ImportCheck::Unknown("Unexpected stderr content: '" + cliResult.stderrContent + "'");
|
return ImportCheck::Unknown("Unexpected stderr content: '" + cliResult.stderrContent + "'");
|
||||||
if (submatches[1] != "File not found" && submatches[1] != "File outside of allowed directories")
|
if (submatches[1] != "File not found" && !boost::starts_with(string(submatches[1]), "File outside of allowed directories"))
|
||||||
return ImportCheck::Unknown("Unexpected error message: '" + cliResult.stderrContent + "'");
|
return ImportCheck::Unknown("Unexpected error message: '" + cliResult.stderrContent + "'");
|
||||||
|
|
||||||
if (submatches[1] == "File not found")
|
if (submatches[1] == "File not found")
|
||||||
return ImportCheck::FileNotFound();
|
return ImportCheck::FileNotFound();
|
||||||
else if (submatches[1] == "File outside of allowed directories")
|
else if (boost::starts_with(string(submatches[1]), "File outside of allowed directories"))
|
||||||
return ImportCheck::PathDisallowed();
|
return ImportCheck::PathDisallowed();
|
||||||
else
|
else
|
||||||
return ImportCheck::Unknown("Unexpected error message '" + submatches[1].str() + "'");
|
return ImportCheck::Unknown("Unexpected error message '" + submatches[1].str() + "'");
|
||||||
|
Loading…
Reference in New Issue
Block a user