-
Notifications
You must be signed in to change notification settings - Fork 8
Better errors with codes and hoa explain
#51
Comments
hoa explain
hoa explain
I like the idea of have a normalized makdown template, related to error code. And i've commonly end up to use Can you give us a detail about |
It does not conflict. We can have nice exception types, and nice codes too. Exception types (sub-classes of
Hmm yes. I understand the need to have a severity attribute on exception, but I would not use
Simply indexing exceptions like 1, 2, 4 for
Good question. What happens if an exception has no code? Well, we won't tell the user to use |
It seems a good idea to use Exception hierarchy to retrieve the last valid code that can be explained. The source exception is often the source of the problem. |
Be careful: We will not be able to use class hierarchy. If a |
That's exactly what I was trying to say, precedence is the right word here (sorry for my english 😄). |
Ok we are on same line, but, look at Hoa Exception today. This is why i'm asking, do we need to refactor our Exception by strictly specify a error code ? as an example, if a method who throws an exception expects to receive an array of strings but receives a number instead, we should throw Can we share code between library ? |
@Pierozi for me the code can still use |
The code is given in the exception constructor, as we always do: throw new MyException($message, $code, $arguments, $previous); |
Yesterday evening, we talked about this RFC during the Hoa Virtual meeting. In Hoa, each exception already exists for a specific need and already have a solid meaning. Relying on exception types instead of creating code may be more relevant. Now, with Kitab, we can add all the documentation above the class declaration with examples. This examples will be tested to be sure the documentation is always valid. The |
If you look at angular js 1, all error come with a link inside the js console to the website of angular. And the website of angular display an explanation on this error. For me like shulard say, Hoa is very specific in his exception, so just with the exception name we could redirect to a website with explanation, overall with kitab. |
@shulard @Grummfy Actually, you're right and I think
All that stuff can be added directly into the documentation. This is OK to cancel an RFC if we have a single tool that addresses several problems or needs. This is actually even better! |
However, if people does not have Kitab installed or an Internet access, we can still have the |
Attached to #51. The PhpCsFixer\AbstractLinesBeforeNamespaceFixer::fixLinesBeforeNamespace signature as changed in PHP-CS-Fixer v2.8.1 : * The offending commit : PHP-CS-Fixer/PHP-CS-Fixer@d3a7101#diff-41cf271d3466dbb2548c606fee86f147L30 Since Hoa rely on the host installed php-cs-fixer binary, we have an edge case to check here...
Since php-cs-fixer is run using the globally installed binary, we must handle edge case / breaking change between version. To be able to detect those incompatibilities, we must be able to check php-cs-fixer verbose output... See #51.
Hello fellow @hoaproject/hoackers and users!
As a direct or indirect user of Hoa, I want better errors than a simple exception backtrace. I want more context about errors.
Introduction
Rust and Elm errors are exemplaries. For instance in Rust:
Or in Elm:
All Rust errors are all listed online. Another interesting blog post from Elm: Compiler errors for humans.
We must provide a better mechanism to understand errors thrown by Hoa libraries. This RFC takes inspiration from the Rust and Elm languages.
Goals
Majority of the time spent on a new project consists of dealing with errors. This RFC will:
Context
So far, Hoa does not trigger any error. Only exceptions are thrown. Each exception is uniquely indexed per class (so 0, 1, 2, 3 for class
C
, 0, 1, 2, 3, 4, 5, 6 for classD
etc). We might revise this indexing to have a similar mechanism to Rust's.Index is stored in the
$code
attribute of theException
class. The code is typed asmixed
so we can store an integer, or a string in it.Error format
By errors, we mean exceptions. An error code is defined by a specific format. In Rust, an error format has the following form:
E[0-9]{4}
. In our case, sure we will not reach the error number E9999, but we can apply a different format, like[A-Z]{3}[0-9]{3}
, where the first letters represents the error prefix, i.e. the library identifier, and followed by the error index. For instance:ACL012
forHoa\Acl
, orRUL007
forHoa\Ruler
, orCOM011
forHoa\Compiler
. Picking the first three letter of the library name is not enought to avoid conflicts, likeHoa\Event
andHoa\Eventsource
that will collide (EVE
in both case). So it can be totally arbitrary, we can takeEVT
forHoa\Event
andESR
forHoa\Eventsource
. This is a possibility. Or we can stick withE[0-9]{4}
but we must set a lock on an error index in one library when creating a new error in another library to avoid having the same index twice (imagine I create 1 new error inHoa\Acl
and 1 new inHoa\Bench
, we need to “reserve” the new error index for one library to ensure the index is unique). Having the[A-Z]{3}[0-9]{3}
format is simpler to manage for a library context.We can use the
$code
attribute of theException
class to store the[0-9]{3}
part. The[A-Z]{3}
might be a meta data attached to the library. Or the$code
attribute can store the whole error code.Explain
Given an error code, we can get more explanations about what leads to it, how to avoid it etc. The new
hoa explain <error_code>
command will show a comprehensive description about this particular error.The description would include this:
The format of the description will be markdown.
Example:
The “Invalid example” and “Valid example” Sections must be strictly named like this. They act as “anchors” for error-based testing, see bellow. All sections can contain zero or more code blocks.
Error list
It will be easy to collect all errors, and publish them online. This will be a good resource for everyone, and it will publicly show we are serious regarding errors.
Error-based testing
Obviously, these error descriptions must be testable. We can extract the code from the examples, compile them to integration test cases, and then run them. All the example code blocks in the “Invalid example” Section are expected to fail. All the example code blocks in the “Valid example” Section are expected to succeed.
What command to run to test the errors? Maybe
hoa test:run
but it will need to scan, parse, compile, and execute error examples each time, a cache would be nice, not discussed here. Engineering issue.Too much errors to manage?
If you think we have too much errors to manage, then this would be because we have too much errors at all. In this case, we must reduce the amount of errors a library can produce. If the number goes too high, it means we might be doing something wrong. This is a good probe.
Location of error descriptions
Just like we have
Bin
,Test
, andDocumentation
at the root of each library, we can addError
, accessible throughhoa://Library/<Name>/Error
, but from my point of view, this must be considered as a documentation, so I would store all the error descriptions inDocumentation/Error/
, just like that:Print exception message
When printing the exception message, instead of printing the exception index as usual, we print:
or, if we store the whole error code in
Exception::$code
, simply printing$exception->getCode()
, not changes required.Outro
What do you think? To be frank, majority of the time I spend on a new project is not coding but dealing with stupid errors. This mechanism will help a lot any new comers.
Thoughts?
The text was updated successfully, but these errors were encountered: