January 14, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On 1/12/19 10:34 AM, Seb wrote: > tl;dr: I was annoyed for years that D's assert are so non informative AssertError, so here's my late Christmas present for the D community. With 2.085 DMD will gain an experimental flag for more informative assertion errors. Feedback on this experimental feature is welcome, s.t. we eventually can enable it by default. [...] > Thanks to all the people (Jacob Carlborg, Petar Kirov, Nicolas Wilson, Rainer Schuetze, etc.) who helped me to get this feature into DMD! > > Merry Christmas! Just want to add in my +1. Thanks! -Steve |
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Saturday, 12 January 2019 at 15:34:02 UTC, Seb wrote:
> void main()
> {
> int a = 1, b = 2;
> assert(a == b); // ERROR: 1 != 2
> }
But 1!=2 is true :)
Maybe do it the C way "assertion 1 == 2 failed"? Also there's in operator.
|
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | And what happens to other expressions? assert(a == b); // ERROR: 1 != 2 assert(c.has(d)); // ERROR: c.has(d) The message will have an opposite meaning? |
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Tuesday, 15 January 2019 at 08:47:24 UTC, Kagamin wrote: > And what happens to other expressions? >.. > assert(c.has(d)); // ERROR: c.has(d) > > The message will have an opposite meaning? https://run.dlang.io/is/mRQM02 --- core.exception.AssertError@onlineapp.d(5): assert(a.has(b)) failed ---------------- ??:? _d_assert_msg [0x2bf174b4] ??:? _Dmain [0x2bf173ed] --- It falls back to printing the stringified raw expression as the changelog states [1]. (this is still an improvement compared to the current "AssertError" without any information) [1] https://dlang.org/changelog/pending.html#assert |
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Tuesday, 15 January 2019 at 08:43:06 UTC, Kagamin wrote:
> On Saturday, 12 January 2019 at 15:34:02 UTC, Seb wrote:
>> void main()
>> {
>> int a = 1, b = 2;
>> assert(a == b); // ERROR: 1 != 2
>> }
>
> But 1!=2 is true :)
> Maybe do it the C way "assertion 1 == 2 failed"? Also there's in operator.
Hmm you have a point there. How do other people feel about this?
My main motivation was to be able to see the actual values (instead of just an AssertError), so I would be more than happy to change the format of the message.
|
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Tuesday, 15 January 2019 at 10:23:32 UTC, Seb wrote:
> My main motivation was to be able to see the actual values (instead of just an AssertError), so I would be more than happy to change the format of the message.
I remember Adam wanted the asserted expression to be printed as is to more reliably locate the failed assert as it can move when the code changes. Did you consider it?
So the message can be "assertion a == b failed: a=1,b=2".
|
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Tue, 15 Jan 2019 10:23:32 +0000, Seb wrote:
> On Tuesday, 15 January 2019 at 08:43:06 UTC, Kagamin wrote:
>> On Saturday, 12 January 2019 at 15:34:02 UTC, Seb wrote:
>>> void main()
>>> {
>>> int a = 1, b = 2;
>>> assert(a == b); // ERROR: 1 != 2
>>> }
>>
>> But 1!=2 is true :)
>> Maybe do it the C way "assertion 1 == 2 failed"? Also there's in
>> operator.
>
> Hmm you have a point there. How do other people feel about this?
>
> My main motivation was to be able to see the actual values (instead of just an AssertError), so I would be more than happy to change the format of the message.
I think I'd agree with Kagamin - after the first time you'd know it, but D already has a big list of "after the first time" features; If we see D-learners posting, confused about it, then it should probably be adjusted; otherwise, maybe it's not a major concern.
I just skimmed some of my tests and the current message works, but may take some getting used to because of the reversal of the conditional. Ex:
assert(opts.imports[0] == "std.stdio");
// becomes "ERROR: std.file != std.stdio"... well, yeah.
// "ERROR: assertion std.file == std.stdio failed" is an easier read
// (at least for me)
--Ryan
|
January 15, 2019 Re: My late christmas present for you: context-aware assertion error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On 2019-01-15 11:23, Seb wrote: > Hmm you have a point there. How do other people feel about this? I think the message should look as similar as the expression in the code as possible. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation