Skip to content

Commit 79af55e

Browse files
committed
CommandLineInterface: Report all errors/infos/warnings with proper severity and coloring
1 parent 963eb15 commit 79af55e

File tree

52 files changed

+82
-62
lines changed
  • solc
  • test
    • cmdlineTests
      • ast_json_import_wrong_evmVersion
      • debug_info_in_yul_and_evm_asm_print_all_and_none
      • debug_info_in_yul_and_evm_asm_print_snippet_only
      • linker_mode_invalid_option_no_optimize_yul
      • linker_mode_invalid_option_optimize_runs
      • linker_mode_invalid_option_optimize_yul
      • linker_mode_invalid_option_optimize
      • linker_mode_invalid_option_yul_optimizations
      • linker_mode_output_selection_invalid
      • linking_strict_assembly_duplicate_library_name
      • model_checker_bmc_loop_iterations_invalid_arg
      • model_checker_bmc_loop_iterations_no_argument
      • model_checker_contracts_contract_missing
      • model_checker_contracts_empty_contract
      • model_checker_contracts_empty_source
      • model_checker_contracts_one_contract_missing
      • model_checker_contracts_source_missing
      • model_checker_ext_calls_empty_arg
      • model_checker_ext_calls_wrong_arg
      • model_checker_invariants_wrong
      • model_checker_print_query_no_smtlib2_solver_bmc
      • model_checker_print_query_no_smtlib2_solver_chc
      • model_checker_print_query_superflous_solver
      • model_checker_solvers_wrong2
      • model_checker_solvers_wrong
      • model_checker_targets_error
      • no_cbor_metadata_with_metadata_hash
      • optimizer_enabled_invalid_yul_optimizer_enabled_and_disabled
      • standard_cli_output_selection_invalid
      • standard_file_not_found
      • standard_invalid_option_no_optimize_yul
      • standard_invalid_option_optimize_runs
      • standard_invalid_option_optimize_yul
      • standard_invalid_option_optimize
      • standard_invalid_option_yul_optimizations
      • stop_after_parsing_abi
      • strict_asm_debug_info_print_snippet_only
      • strict_asm_invalid_option_output_dir
      • strict_asm_optimizer_invalid_yul_optimizer_enabled_and_disabled
      • strict_asm_options_in_non_asm_mode
      • strict_asm_output_selection_invalid
      • yul_optimizer_steps_disabled
      • yul_optimizer_steps_invalid_abbreviation
      • yul_optimizer_steps_nesting_too_deep
      • yul_optimizer_steps_unbalanced_closing_bracket
      • yul_optimizer_steps_unbalanced_opening_bracket
      • ~unknown_options
    • solc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+82
-62
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions

solc/CommandLineInterface.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void CommandLineInterface::readInputFiles()
517517
if (!m_options.input.ignoreMissingFiles)
518518
solThrow(CommandLineValidationError, '"' + infile.string() + "\" is not found.");
519519
else
520-
serr() << infile << " is not found. Skipping." << std::endl;
520+
report(Error::Severity::Info, fmt::format("\"{}\" is not found. Skipping.", infile.string()));
521521

522522
continue;
523523
}
@@ -527,7 +527,7 @@ void CommandLineInterface::readInputFiles()
527527
if (!m_options.input.ignoreMissingFiles)
528528
solThrow(CommandLineValidationError, '"' + infile.string() + "\" is not a valid file.");
529529
else
530-
serr() << infile << " is not a valid file. Skipping." << std::endl;
530+
report(Error::Severity::Info, fmt::format("\"{}\" is not a valid file. Skipping.", infile.string()));
531531

532532
continue;
533533
}
@@ -639,7 +639,7 @@ bool CommandLineInterface::run(int _argc, char const* const* _argv)
639639
// There might be no message in the exception itself if the error output is bulky and has
640640
// already been printed to stderr (this happens e.g. for compiler errors).
641641
if (_exception.what() != ""s)
642-
serr() << _exception.what() << std::endl;
642+
report(Error::Severity::Error, _exception.what());
643643

644644
return false;
645645
}
@@ -817,7 +817,7 @@ void CommandLineInterface::compile()
817817
{
818818
if (_error.type() == Error::Type::DocstringParsingError)
819819
{
820-
serr() << *boost::get_error_info<errinfo_comment>(_error);
820+
report(Error::Severity::Error, *boost::get_error_info<errinfo_comment>(_error));
821821
solThrow(CommandLineExecutionError, "Documentation parsing failed.");
822822
}
823823
else
@@ -1020,7 +1020,10 @@ void CommandLineInterface::link()
10201020
copy(hexStr.begin(), hexStr.end(), it);
10211021
}
10221022
else
1023-
serr() << "Reference \"" << foundPlaceholder << "\" in file \"" << src.first << "\" still unresolved." << std::endl;
1023+
report(
1024+
Error::Severity::Warning,
1025+
fmt::format("Reference \"{}\" in file \"{}\" still unresolved.", foundPlaceholder, src.first)
1026+
);
10241027
it += placeholderSize;
10251028
}
10261029
// Remove hints for resolved libraries.
@@ -1136,7 +1139,7 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
11361139
if (object.bytecode)
11371140
sout() << object.bytecode->toHex() << std::endl;
11381141
else
1139-
serr() << "No binary representation found." << std::endl;
1142+
report(Error::Severity::Info, "No binary representation found.");
11401143
}
11411144
if (m_options.compiler.outputs.astCompactJson)
11421145
{
@@ -1150,7 +1153,7 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
11501153
if (!object.assembly.empty())
11511154
sout() << object.assembly << std::endl;
11521155
else
1153-
serr() << "No text representation found." << std::endl;
1156+
report(Error::Severity::Info, "No text representation found.");
11541157
}
11551158
}
11561159
}
@@ -1220,4 +1223,16 @@ void CommandLineInterface::outputCompilationResults()
12201223
}
12211224
}
12221225

1226+
void CommandLineInterface::report(langutil::Error::Severity _severity, std::string _message)
1227+
{
1228+
SourceReferenceFormatter::printPrimaryMessage(
1229+
serr(),
1230+
_message,
1231+
_severity,
1232+
std::nullopt,
1233+
coloredOutput(m_options),
1234+
m_options.formatting.withErrorIds
1235+
);
1236+
}
1237+
12231238
}

solc/CommandLineInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class CommandLineInterface
136136
/// stream has ever been used unless @arg _markAsUsed is set to false.
137137
std::ostream& serr(bool _markAsUsed = true);
138138

139+
void report(langutil::Error::Severity _severity, std::string _message);
140+
139141
std::istream& m_sin;
140142
std::ostream& m_sout;
141143
std::ostream& m_serr;

test/cmdlineTests.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ EOF
318318
## RUN
319319

320320
printTask "Testing passing files that are not found..."
321-
test_solc_behaviour "file_not_found.sol" "" "" "" 1 "" "\"file_not_found.sol\" is not found." "" ""
321+
test_solc_behaviour "file_not_found.sol" "" "" "" 1 "" "Error: \"file_not_found.sol\" is not found." "" ""
322322

323323
printTask "Testing passing files that are not files..."
324-
test_solc_behaviour "." "" "" "" 1 "" "\".\" is not a valid file." "" ""
324+
test_solc_behaviour "." "" "" "" 1 "" "Error: \".\" is not a valid file." "" ""
325325

326326
printTask "Testing passing empty remappings..."
327-
test_solc_behaviour "${0}" "=/some/remapping/target" "" "" 1 "" "Invalid remapping: \"=/some/remapping/target\"." "" ""
328-
test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "" "Invalid remapping: \"ctx:=/some/remapping/target\"." "" ""
327+
test_solc_behaviour "${0}" "=/some/remapping/target" "" "" 1 "" "Error: Invalid remapping: \"=/some/remapping/target\"." "" ""
328+
test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "" "Error: Invalid remapping: \"ctx:=/some/remapping/target\"." "" ""
329329

330330
printTask "Running general commandline tests..."
331331
(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Failed to import AST: Imported tree evm version differs from configured evm version!
1+
Error: Failed to import AST: Imported tree evm version differs from configured evm version!
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Invalid value for --debug-info option: location,all,none
1+
Error: Invalid value for --debug-info option: location,all,none
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
To use 'snippet' with --debug-info you must select also 'location'.
1+
Error: To use 'snippet' with --debug-info you must select also 'location'.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Option --no-optimize-yul is only valid in compiler and assembler modes.
1+
Error: Option --no-optimize-yul is only valid in compiler and assembler modes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Option --optimize is only valid in compiler and assembler modes.
1+
Error: Option --optimize is only valid in compiler and assembler modes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Option --optimize-runs is only valid in compiler and assembler modes.
1+
Error: Option --optimize-runs is only valid in compiler and assembler modes.

0 commit comments

Comments
 (0)