Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error messages, eg: report indexes and shape instead of static text #1

Closed
timotheecour opened this issue Jan 9, 2016 · 10 comments

Comments

@timotheecour
Copy link

timotheecour commented Jan 9, 2016

these error messages are not very helpful for debugging:
https://github.com/DlangScience/mir/blob/master/source/mir/ndslice/slice.d#L854 [+ elsewhere similar]

assert(_indexes[0][i] < _lengths[i], "indexStride: index must be less than lengths");

how about instead:

version(assert)
  enforce(_indexes[0][i] < _lengths[i], text("indexStride: index must be less than lengths", _indexes[0][i], " ", _lengths[i], " ", i));

NOTE: not sure if there's a better way to do it, but i want to have the check only in -release mode (hence version(assert)), and I want to avoid runtime cost in forming a text(..) expression when the assert passes, hence the enforce(boo, lazy exp)

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/29736892-better-error-messages-eg-report-indexes-and-shape-instead-of-static-text?utm_campaign=plugin&utm_content=tracker%2F18251717&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18251717&utm_medium=issues&utm_source=github).
@9il
Copy link
Member

9il commented Jan 10, 2016

I can add information about position:
[a, b, c]// a at 0 ,b at 1, and c at 2 positions
Any exceptions or GC allocations are not allowed for Slice. ndslice is @nogc library except reshape and sliced (with default flag).

@timotheecour
Copy link
Author

just wrote this: hacky but works:
formatted assert error messages inside nogc functions
http://forum.dlang.org/thread/mailman.3496.1452412496.22025.digitalmars-d@puremagic.com

while waiting for a fix to https://issues.dlang.org/show_bug.cgi?id=13055

@9il
Copy link
Member

9il commented Jan 10, 2016

@safe and pure?

@9il
Copy link
Member

9il commented Jan 10, 2016

@safe can be hacked with @trusted

@timotheecour
Copy link
Author

and pure can be worked around in debug mode [updated thread]:

@nogc @trusted pure
void test(int a){
  if(!(a==3)){
    debug{
    char[100]buf; //TODO:make sure big enough
    // would like to use 'auto s=sformat(buf, "a = %s", a);' but not nogc: https://issues.dlang.org/show_bug.cgi?id=13055 
    auto m=snprintf(buf.ptr, buf.length, "a = %d", a);
    assert(m<buf.length && m>0);
    assert(0, buf[0..m]);
    }
    else{
      assert(0);
    }
  }
}

now this should be made into something more generic and reusable...

@9il
Copy link
Member

9il commented Jan 10, 2016

Looks like it is better to implement own function for integers in the package.

@timotheecour
Copy link
Author

what do you mean?

@9il
Copy link
Member

9il commented Jan 10, 2016

what do you mean?

const(char)[] localText(T...)(char[] buff, T values) {
///must work with integers and strings
}

@timotheecour
Copy link
Author

+1 [ugly is ok while waiting for a better solution, eg rcstring or https://issues.dlang.org/show_bug.cgi?id=13055 ]

@9il
Copy link
Member

9il commented Sep 9, 2018

does not related to this repo anymore

@9il 9il closed this as completed Sep 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants