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

How to debug the handlers? #146

Open
zhangzq opened this issue Jan 26, 2021 · 6 comments
Open

How to debug the handlers? #146

zhangzq opened this issue Jan 26, 2021 · 6 comments

Comments

@zhangzq
Copy link

zhangzq commented Jan 26, 2021

My app showed me an error message:

ERROR: [connection:5] error while handling request: basic_string::_M_replace_aux

I didn't know where the error cames from (even I compiled in debug mode and run in gdb). What should I do?

@eao197
Copy link
Member

eao197 commented Jan 26, 2021

Hi!

Looks like you get a std::length_error somewhere in your request-handler. That exception is caught by RESTinio and logger.

It's hard to help you because I don't know anything about your code. You can try to place the code in your request-handler into try-catch block:

auto my_request_handler(const restinio::request_handle_t & req) {
  try {
    ... // Your code here.
  }
  catch(const std::exception & x) {
    std::cerr << "Oops! " << x.what() << std::endl; // (1)
  }
}

Then set a breakpoint at (1).

@zhangzq
Copy link
Author

zhangzq commented Jan 26, 2021

Is there an MACRO -- not to catch the exception and let the app core dump, then let me check the error stack (in gdb)?

@eao197
Copy link
Member

eao197 commented Jan 26, 2021

No, there is no such a macro.

You can comment try/catch blocks here:

catch( const std::exception & ex )
{
trigger_error_and_close( [&]{
return fmt::format(
"[connection:{}] error while handling request: {}",
this->connection_id(),
ex.what() );
} );
}

@zhangzq
Copy link
Author

zhangzq commented Jan 26, 2021

Hi!

Looks like you get a std::length_error somewhere in your request-handler. That exception is caught by RESTinio and logger.

It's hard to help you because I don't know anything about your code. You can try to place the code in your request-handler into try-catch block:

auto my_request_handler(const restinio::request_handle_t & req) {
  try {
    ... // Your code here.
  }
  catch(const std::exception & x) {
    std::cerr << "Oops! " << x.what() << std::endl; // (1)
  }
}

Then set a breakpoint at (1).

Breakpoint at (1) won't provide the error stack.

@zhangzq
Copy link
Author

zhangzq commented Jan 26, 2021

No, there is no such a macro.

You can comment try/catch blocks here:

catch( const std::exception & ex )
{
trigger_error_and_close( [&]{
return fmt::format(
"[connection:{}] error while handling request: {}",
this->connection_id(),
ex.what() );
} );
}

Thanks. I comment/uncomment using #ifdef DBUG, but get catched by some other place and show error messsage:

unexpected exception during the handling of incoming data: basic_string::_M_replace_aux

@eao197
Copy link
Member

eao197 commented Jan 26, 2021

Breakpoint at (1) won't provide the error stack.

Oops. Ok. Let's try something like that:

class dummy_breakpoint {
  bool commited_{false};
public:
  dummy_breakpoint() = default;
  ~dummy_breakpoint() { if(!commited_) std::abort(); } // or just throw std::runtime_error("my exception");

  void commit() { commited_ = true; }
};

// Then in your request-handler:
auto my_request_handler(const restinio::request_handle_t & req) {
  dummy_breakpoint breakpoint;
  ...
  const auto res = req->create_response(...)...;
  dummy_breakpoint.commit();
  return res;
}

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