argotorg / argotorg/solidity

Graceful handling of non-ICE exceptions

Open
#15,139 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

annoys users :cry: medium effort medium impact must have
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

Abstract

Currently exceptions such as UnimplementedFeatureError, CodeGenerationError, StackTooDeepError and CompilerError are reported as internal compiler errors, i.e. by completely interrupting what the compiler is doing and printing out diagnostic information that's meant to help with tracking down a bug in the compiler. This behavior is appropriate for development assertions, which generally won't fail unless there is a bug, but not for errors that users will normally encounter when compiling their code.

Motivation

The current behavior is very confusing to users as evidenced by the discussion thread in #12783.

There have been some limited attempts at improving this, for example we do catch UnimplementedFeatureError if it carries a source location. Unfortunately this is not nearly enough. The solUnimplementedAssert() macro for raising such errors does not even allow attaching a location, so it is uncommon to have one, even when it is easy to obtain. E.g. in #14913 the obvious thing to do would be to point at the problematic require() call. Instead the user gets diagnostic info pointing at a location in the compiler's source, which is useless in that context. In other cases, like https://github.com/ethereum/solidity/pull/15001#discussion_r1603214954, this limitation leads to dropping otherwise useful tests.

Specification

There are several things we should do to address this situation:

  • UnimplementedFeatureError, CodeGenerationError, StackTooDeepError and CompilerError should be caught and reported as proper compilation errors even if they do not have a location.
  • The errors should include location where possible:
    • solUnimplemented() should allow including location.
    • solUnimplementedAssert() should be removed to avoid suggesting that it's an assertion like solAssert(). It's actually a validation.
      • Its message parameter should have been mandatory. A message for the user should always be provided with such errors.
    • Add locations to the current uses of UnimplementedFeatureError where available. There aren't that many of them and it will greatly improve user experience.
    • For cases where location is not known we could try iterating on Daniel's attempt at obtaining the location automatically.
  • Review existing handlers for these exceptions. After doing the above most of them should not be necessary. All these errors inherit from util::Exception and if not caught where we expect them, they should generally be treated as any other unexpected exception by the top-level handler.

Backwards Compatibility

I don't think there are any backwards-compatibility concerns associated with this change. Currently these exceptions produce diagnostic output that is platform-dependent and we don't guarantee its stability in any way.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in libsolidity/interface/CompilerStack.cpp, especially the existing UnimplementedFeatureError handling, then review the solUnimplemented() and solUnimplementedAssert() uses and existing exception handlers. Compare the behavior discussed in #12783, #14913, and pull request #15001. Done means the listed exceptions become proper compilation errors, with source locations and user messages where available, while unnecessary handlers are removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.