a-luna / aaronluna.dev

My personal website/blog/portfolio, built with Hugo
https://aaronluna.dev
3 stars 1 forks source link

blog/error-handling-python-result-class/ #208

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Error Handling in Python: Result Class - aaronluna.dev

In a previous post, I explained how concepts from functional programming can be incorporated with object-oriented code to improve the tedious and mandatory task of error handling and input validation through the use of the Result class. That post explained how to implement the Result class in C#. Since I have been writing mostly Python code lately, I created a new implementation and documented its use. Due to Python’s duck-typing, this implementation is (IMO) more natural and makes reasoning about the code it supports much easier.

https://aaronluna.dev/blog/error-handling-python-result-class/

AnushaKoripally commented 3 years ago

Hi Aaron,

I am new to Python. I am trying to use your Result class....and returning Result.ok()

in app.py I have like this

def insert_items(): return insert_newstreet("1", "AbC")

in insert_newstreet class i am returning Result.ok()

I am getting an error saying String,Tuple or object is expected but Result is being returned.

Can you help me with this?

mirzafahad commented 3 years ago

Thanks for the idea. I was looking for a way to gracefully handle success/failure situations. This fit the bill perfectly!