Comments (4)
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.
Thanks @todofixthis for the explanation, I'm gonna include it in for #310.
from iota.py.
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.
@todofixthis I'm talking about this exception:
iota.py/iota/commands/extended/promote_transaction.py
Lines 38 to 43 in 9416068
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)
- Remove tips parameter from get_inclusion_states API call
- `get_bundles` returns bundle object when no bundle was found
- Increase test coverage for `IsReattachableCommand`
- Add tests for `get_bundles_from_transaction_hashes`
- Async code examples
- PY2 -> PY3 Migration
- Document possible exceptions in api methods
- Remove threshold parameter from `getBalance` command
- Remove `get_tips` api command
- Add `is_confirmed` alias for `get_inclusion_states`
- Update references of https://devnet.thetangle.org
- Incompatibility with pyinstaller HOT 2
- Update PyOTA for comnet
- Fix typo in docs parameter description HOT 1
- Removal of checkConsistency
- SSLError: HTTPSConnectionPool(host='nodes.devnet.iota.org', port=443)
- Pyota library error after compiling the file to exe HOT 7
- Building wheel for pysha3 (setup.py) error on Ubuntu 18.04.5 LTS Python 3.7.5 HOT 2
- Errors in tutorial 02_send_data.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iota.py.