Giter VIP home page Giter VIP logo

Comments (4)

todofixthis avatar todofixthis commented on July 17, 2024 1

with_context is meant to be a way for developers to include other relevant information with the exception that is more lightweight than trawling through the stack frames.

Including the information in the exception message is often convenient, but sometimes not (e.g., the context for an exception might be a bundle, and that means a VERY long exception message!).

Attaching additional information to the exception requires a bit of extra effort on the application developer's part, but it opens up additional options for troubleshooting.

E.g.,:

try:
  pt_response = api.promote_transaction(...)
except BadApiResponse as e:
  # Production scenario:
  # Log exception details to database, log, DLQ, etc. for forensics.
  log_to_database(e.message, e.context, # etc.

  # Development scenario:
  # Display context information with the exception, to make it easier to debug the issue.
  pprint(e.context)
  raise

In particular, I used this technique on a previous project that logged exceptions (and their context values) to a database, which proved invaluable for diagnosing errors that occurred on production.

Additionally, for developers who are not familiar with PyOTA internals, this gives them a way to inspect/debug values that are relevant to the exception, in a way that doesn't require them to edit/debug 3rd-party code.

from iota.py.

lzpap avatar lzpap commented on July 17, 2024 1

Thanks @todofixthis for the explanation, I'm gonna include it in for #310.

from iota.py.

todofixthis avatar todofixthis commented on July 17, 2024

The response payload should already be included in the context attribute of the exception:
https://github.com/iotaledger/iota.py/blob/master/iota/adapter/__init__.py#L484-L496

from iota.py.

lzpap avatar lzpap commented on July 17, 2024

@todofixthis I'm talking about this exception:

cc_response = CheckConsistencyCommand(self.adapter)(tails=[transaction])
if cc_response['state'] is False:
raise BadApiResponse(
'Transaction {transaction} is not promotable. '
'You should reattach first.'.format(transaction=transaction)
)

The response from the node should be alright from the adapter's perspective, it it should contain status, info and duration fields.

Btw a question: how are exceptions raised with with_context should be handled in application code? What is the best practice to get also the context and not just the error message written to the output?

from iota.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.