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

Improved assert output #178

Open
jlp765 opened this issue Jan 3, 2023 · 4 comments
Open

Improved assert output #178

jlp765 opened this issue Jan 3, 2023 · 4 comments

Comments

@jlp765
Copy link
Contributor

jlp765 commented Jan 3, 2023

Could the line of the source code with the assertion be shown, eg, something like:

Assertion Failure
  assert n < 24;
Felix location: .../test.flx 2[3]-2[17]

for

fun test (n) : bool = {
  assert n < 24;
  return true;
}
println$ test 48;

Current output:

Felix exception handler
Assertion Failure
Felix location: .../test.flx 2[3]-2[17]
C++ location  : ..../test.cpp 39
Error 253 in flx: Unknown error 253
@skaller
Copy link
Member

skaller commented Jan 4, 2023

#define FLX_ASSERT_FAILURE(f,sl,sc,el,ec) \
  throw ::flx::rtl::flx_assert_failure_t (::flx::rtl::flx_range_srcref_t(f,sl,sc,el,ec),__FILE__,__LINE__)

and

struct FLX_EXCEPTIONS_EXTERN flx_assert_failure_t : flx_exception_t {
  flx_range_srcref_t flx_loc; ///< location in Felix file
  char const *cxx_srcfile;          ///< C++ file
  int cxx_srcline;            ///< __LINE__ macro
  flx_assert_failure_t(flx_range_srcref_t ff, char const *cf, int cl);
  virtual ~flx_assert_failure_t();
};

handler:

  else
  if (flx_assert_failure_t const *x = dynamic_cast<flx_assert_failure_t const*>(e))
  {
    fprintf(stderr,"Assertion Failure\n");
    print_loc(stderr,x->flx_loc,x->cxx_srcfile, x->cxx_srcline);
    return 3;
  }
  else

So we could try finding the line and printing it. Open the file, do nothing on failure.
grab the line .. you'd have to read all the lines up to the culprit.
Then you can send it to stderr with a message.

@skaller
Copy link
Member

skaller commented Jan 4, 2023

EH is in src/packages/exceptions.fdoc

Use 'make rebuild' to rebuild the run time library.

@jlp765
Copy link
Contributor Author

jlp765 commented Jan 9, 2023

Before I commit a PR, is the following acceptable?

If there are multiple lines of code (which I assume is unusal for an assert), the 2nd ... lines all indent to match the first line, aligning to after the Felix code:

Felix exception handler
Assertion Failure
Felix code: assert x < 19;
Felix location: ........./test_assert.flx 2[1]-2[15]
C++ location  : ........./test_assert.cpp 32
Error 3 in flx: [strerror_r] Failed to find text for error number 3

@skaller
Copy link
Member

skaller commented Jan 9, 2023

Yeah although it occurs to me that an assert failure is only going to show an assert that failed. Maybe show the line before and the line after for context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants