SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
2014-10-{23,24} 
Managing errors the 
right way in Scala 
François ARMAND 
CTO - Normation 
far@normation.com
Say hello ! 
François ARMAND 
far@normation.com / @fanf42 
Co-founder & CTO Lead-dev 
Discovered Scala 
in 2006 
OSS convinced 
Full time Scala 
since 2009 And yes, I'm trying to start a side 
business in cloning
What's about ? 
The primary duty of an exception handler is to get 
the error out of the lap of the programmer and into 
the surprised face of the user. Provided you keep this 
cardinal rule in mind, you can't go far wrong. 
— Verity Stob 
Managing errors so that both futur developpers, 
ops and users are happy is what differentiate 
hacking toys projects to building softwares 
— Myself
What's about ? 
Sharing the (hard) learned lessons 
about managing errors in Scala in 
our 5 years trip with Rudder
What's about ? 
http://www.rudder-project.org 
IT infratructure 
open source automation 
+ 
compliance management 
Server Compliance Agents 
Scala web application 
Started in 2009 
By ex-java dev
Errors ? What's an error ? 
Something didn't worked as it should 
■ Who MUST care ? 
■ Who MUST handle the problem ?
Errors classical classification 
▣ Pop culture(1) say : 
▣ Technical Errors 
■ When your containing universe fails 
□ Ex : « oups, the underlying OS just ran out of memory » 
□ OutOfMemroy Errors, Threads killed, VM crashes... 
■ Logical / modeling error 
□ « no, you really can't access item #42 of that array of size 2 » 
■ Systems in relation with yours failed 
□ Ex : « hello Database ? Helloooooo ? » 
□ Mostly I/O errors : connection errors, bad permession on FS... 
▣ Business Errors 
■ The one the user want to know about 
■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » 
[1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
Errors classical classification 
That's the end of 
the universe, don't 
care (ops will awake) 
▣ Pop culture(1) say : It's complicated : 
▣ Technical Errors 
■ When your containing universe fails 
□ Ex : « oups, the underlying OS just ran out of memory » 
□ OutOfMemroy Errors, Threads killed, VM crashes... 
■ Logical / modeling error 
□ « no, you really can't access item #42 of that array of size 2 » 
■ Systems in relation with yours failed 
□ Ex : « hello Database ? Helloooooo ? » 
□ Mostly I/O errors : connection errors, bad permession on FS... 
▣ Business Errors 
■ The one the user want to know about 
■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » 
[1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
Errors classical classification 
That's the end of 
the universe, don't 
care (ops will awake) 
▣ Pop culture(1) say : It's complicated : 
▣ Technical Errors 
■ When your containing universe fails 
□ Ex : « oups, the underlying OS just ran out of memory » 
□ OutOfMemroy Errors, Threads killed, VM crashes... 
■ Logical / modeling error 
That should be 
modeled in data type 
□ « no, you really can't access item #42 of that array of size 2 » 
■ Systems in relation with yours failed 
□ Ex : « hello Database ? Helloooooo ? » 
□ Mostly I/O errors : connection errors, bad permession on FS... 
▣ Business Errors 
■ The one the user want to know about 
■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » 
[1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
Errors classical classification 
That's the end of 
the universe, don't 
care (ops will awake) 
▣ Pop culture(1) say : It's complicated : 
▣ Technical Errors 
■ When your containing universe fails 
□ Ex : « oups, the underlying OS just ran out of memory » 
□ OutOfMemroy Errors, Threads killed, VM crashes... 
■ Logical / modeling error 
That should be 
modeled in data type 
□ « no, you really can't access item #42 of that array of size 2 » 
■ Systems in relation with yours failed 
Always the business 
□ Ex : « hello Database ? Helloooooo ? » 
□ Mostly I/O errors : connection errors, bad permession on FS... 
▣ Business Errors 
of somebody : 
dev, ops, final user 
■ The one the user want to know about 
■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » 
[1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
Errors classical classification 
That's the end of 
the universe, don't 
care (ops will awake) 
▣ Pop culture(1) say : It's complicated : 
▣ Technical Errors 
■ When your containing universe fails 
□ Ex : « oups, the underlying OS just ran out of memory » 
□ OutOfMemroy Errors, Threads killed, VM crashes... 
■ Logical / modeling error 
That should be 
modeled in data type 
□ « no, you really can't access item #42 of that array of size 2 » 
■ Systems in relation with yours failed 
Always the business 
□ Ex : « hello Database ? Helloooooo ? » 
□ Mostly I/O errors : connection errors, bad permession on FS... 
▣ Business Errors 
of somebody : 
dev, ops, final user 
■ The one the user want to know about 
■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » 
[1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
So, what was our trip in error management land ?
Origins : the dark age of Java Exceptions 
▣ Using Java Exception 
■ Worst : Business and Technical Exception, enterprisy style
Origins : the dark age of Java Exceptions 
Problems ? 
▣ Death by one thousand different GoTos 
▣ Can't reason about part of the code 
■ Hard to understand 
■ Hard to compose 
■ Hard to refactor 
■ Hard to reuse 
▣ Exception are the incarnation of side effect 
Error management must be referentially transparent
Origins : the dark age of Java Exceptions 
Problems ? 
▣ Dilution of responsability 
■ Nobody ever manage exception in a systematic way 
■ Idem in language with error code (C, Python, Go...) 
▣ Human being are not very disciplined 
■ That why we automate things
Origins : the dark age of Java Exceptions 
Problems ? 
▣ Human being are not very disciplined 
▣ But hey ! Compilers DO ARE very disciplined 
▣ Crazy idea: 
■ Force the user to take care of failure to reach success values 
■ Use a data type denoting Error Or Success 
▣ Nice side effects: 
■ Clear identification function that could fail in return type 
■ Errors as value enable referential transparency 
Model faillible code with Algebraic Data Type
Origins : the dark age of Java Exceptions 
Exception: far better tools exists (in Scala)
Option to the rescue (really?) 
▣ Functionnal programming 101 : use option 
■ Option[+A] 
□ None 
□ Some[+A](x: A) 
Need a rich failure type
Option – just to denote missing things 
Option : good data type. Not for error. 
Its semantic is « MISSING ITEM »
Either to the rescue (ok, still no) 
▣ Functionnal programming 101, page 2 : use disjunction 
Either[L,R] : Left[L] : failure and Right[R] : success 
But....
Either to the rescue (ok, still no) 
▣ Functionnal programming 101, page 2 : use disjunction 
Either[L,R] : Left[L] : failure and Right[R] : success 
??? 
Ticket #SI-5793, close won't fix 
No boilerplate !
Either – for the boilerplate lovers 
Either (Scala stdlib): not tailored for errors
Nice try 
▣ Try[A] – essentially an Either[Throwable, A] 
■ Nice on paper (not used in real life) 
□ Even with theoric hole (see « Try and monad laws ») 
■ But really ? Everything is an exception ? 
Need a rich failure type
Try – when all your errors are exception 
Try: NOT ALL errors are exceptions 
Oh, and what could go wrong with ignoring theory ?
A Lift gift in a Box 
▣ Lift, that new web framework (2009 style) 
▣ Box[T] : data structure with 3 cases : 
■ Full[+A](value: A) extends Box[A] 
□ a success that hold your item of type T 
■ EmptyBox extends Box[Nothing] (abstract) 
□ Empty : no results (None for Option) extends EmptyBox 
□ Failure(msg: String, exception: Box[Throwable] 
, chain: Box[Failure]) extends EmptyBox
A Lift gift in a Box
A Lift gift in a Box – with error tooling !
A Lift gift in a Box – with error tooling ! 
Tooling and error lexical field helps
A Lift gift in a Box – with error tooling ! 
But....
So bad it was offered by Pandora 
▣ getUser(User("fanf42")) === Empty. 
■ What do you thing it means ? 
■ Depending of the dev, the refactorer, the tests, it's an error without 
message. 
■ Or a missing item. 
▣ In Rudder, the most surprising error where due to Empty 
■ Surprise is a bad thing: Empty is forbidden. 
■ Object DB { def getUser(id : UserId) : Box[Option[User]] } 
Must be Unambiguious
(Pandora) Box might have been good 
Box: good tooling, too much ambiguity
Finally, let's go shopping ? 
So, no error management framework ?
Desirable properties of error management 
Error management must be referentially transparent 
Model faillible code with Algebraic Data Type 
Must be Unambiguious 
Need a rich failure type 
No boilerplate ! 
Tooling and error lexical field helps
It's a kind of magic 
▣ You know what ? People worked on theory about that. 
■ Theory-backed model free you mind : you know it WILL work. It's proved 
■ http://typelevel.org/blog/2014/02/21/error-handling.html 
■ http://stackoverflow.com/questions/12307965/method-parameters-validation-in-scala- 
with-for-comprehension-and-monads/12309023#12309023
Theory says 
Independant Errors Dependant Errors 
▣ Form validation 
▣ Accumulate them 
▣ « best-effort » 
▣ List of I/O actions 
▣ Chain them 
▣ Stop early 
Scalaz.Validation 
(applicative functor) 
Scalaz./ 
(monad)
Independant Errors 
▣ Form validation 
▣ Accumulate them 
▣ « best-effort » 
Theory says 
Scalaz.Validation 
(applicative functor)
Scalaz.Validation – accumulating errrors 
▣ It's an applicative functor : no for-comprehension
Theory says 
Dependant Errors 
▣ List of I/O actions 
▣ Chain them 
▣ Stop early 
Scalaz./ 
(monad)
Scalaz disjunction – a sane Either
So, no shopping after all ? 
▣ Validation is great for applicative style failure. 
■ It's more generic / less powerful 
■ In fact only used in very specific cases 
▣ / is great for general error management 
■ Toward monadic application 
▣ But...
Tooling on top of / (and Validation) 
▣ Nothing in / is in the semantic domain of errors. 
▣ And it's desirable to have : 
■ One default generic Failure data structure 
■ With tooling (message, root cause, etc) 
■ À la Box. 
▣ Some leads to follow : 
■ Design your own Failure with sugar to add messages / Throwable 
■ User library extension with implicit to add more sugar 
What follows are JUST ideas and example
Tooling on top of / (and Validation) 
A dedicated Fail data type
Tooling on top of / (and Validation) 
A dedicated Error data type
Tooling on top of / (and Validation)
Tooling on top of / (and Validation)
2014-10-{23,24} 
Questions ? 
François ARMAND 
far@normation.com / @fanf42 
Code available on GitHub : https://github.com/fanf/scalaio_2014

Contenu connexe

En vedette

Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception HandlingLemi Orhan Ergin
 
AWS Black Belt Tech シリーズ 2015 - Amazon Kinesis
AWS Black Belt Tech シリーズ 2015 - Amazon KinesisAWS Black Belt Tech シリーズ 2015 - Amazon Kinesis
AWS Black Belt Tech シリーズ 2015 - Amazon KinesisAmazon Web Services Japan
 
Thomas Lamirault_Mohamed Amine Abdessemed -A brief history of time with Apac...
Thomas Lamirault_Mohamed Amine Abdessemed  -A brief history of time with Apac...Thomas Lamirault_Mohamed Amine Abdessemed  -A brief history of time with Apac...
Thomas Lamirault_Mohamed Amine Abdessemed -A brief history of time with Apac...Flink Forward
 
Functional Database Strategies at Scala Bay
Functional Database Strategies at Scala BayFunctional Database Strategies at Scala Bay
Functional Database Strategies at Scala BayJason Swartz
 

En vedette (6)

Scala profiling
Scala profilingScala profiling
Scala profiling
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
 
AWS Black Belt Tech シリーズ 2015 - Amazon Kinesis
AWS Black Belt Tech シリーズ 2015 - Amazon KinesisAWS Black Belt Tech シリーズ 2015 - Amazon Kinesis
AWS Black Belt Tech シリーズ 2015 - Amazon Kinesis
 
Thomas Lamirault_Mohamed Amine Abdessemed -A brief history of time with Apac...
Thomas Lamirault_Mohamed Amine Abdessemed  -A brief history of time with Apac...Thomas Lamirault_Mohamed Amine Abdessemed  -A brief history of time with Apac...
Thomas Lamirault_Mohamed Amine Abdessemed -A brief history of time with Apac...
 
Functional Database Strategies at Scala Bay
Functional Database Strategies at Scala BayFunctional Database Strategies at Scala Bay
Functional Database Strategies at Scala Bay
 
Exception Handling in Scala
Exception Handling in ScalaException Handling in Scala
Exception Handling in Scala
 

Plus de RUDDER

What if configuration management didn't need to be lvl60 in dev?
What if configuration management didn't need to be lvl60 in dev?What if configuration management didn't need to be lvl60 in dev?
What if configuration management didn't need to be lvl60 in dev?RUDDER
 
Servers compliance: audit, remediation, proof
Servers compliance: audit, remediation, proofServers compliance: audit, remediation, proof
Servers compliance: audit, remediation, proofRUDDER
 
OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?
OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?
OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?RUDDER
 
OW2Con - Configurations, do you prove yours?
OW2Con - Configurations, do you prove yours?OW2Con - Configurations, do you prove yours?
OW2Con - Configurations, do you prove yours?RUDDER
 
The new plugin ecosystem in RUDDER 5.0
The new plugin ecosystem in RUDDER 5.0The new plugin ecosystem in RUDDER 5.0
The new plugin ecosystem in RUDDER 5.0RUDDER
 
What uses for observing operations of Configuration Management?
What uses for observing operations of Configuration Management?What uses for observing operations of Configuration Management?
What uses for observing operations of Configuration Management?RUDDER
 
UX challenges of a UI-centric config management tool
UX challenges of a UI-centric config management toolUX challenges of a UI-centric config management tool
UX challenges of a UI-centric config management toolRUDDER
 
What happened in RUDDER in 2018 and what’s next?
What happened in RUDDER in 2018 and what’s next?What happened in RUDDER in 2018 and what’s next?
What happened in RUDDER in 2018 and what’s next?RUDDER
 
What is RUDDER and when should I use it?
What is RUDDER and when should I use it?What is RUDDER and when should I use it?
What is RUDDER and when should I use it?RUDDER
 
Fosdem - Configurations do you prove yours?
Fosdem - Configurations  do you prove yours?Fosdem - Configurations  do you prove yours?
Fosdem - Configurations do you prove yours?RUDDER
 
L'audit en continu : clé de la conformité démontrable (#POSS 2018)
L'audit en continu : clé de la conformité démontrable (#POSS 2018)L'audit en continu : clé de la conformité démontrable (#POSS 2018)
L'audit en continu : clé de la conformité démontrable (#POSS 2018)RUDDER
 
Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)
Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)
Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)RUDDER
 
Stay up - voyage d'un éditeur de logiciels libres
Stay up - voyage d'un éditeur de logiciels libresStay up - voyage d'un éditeur de logiciels libres
Stay up - voyage d'un éditeur de logiciels libresRUDDER
 
How we scaled Rudder to 10k, and the road to 50k
How we scaled Rudder to 10k, and the road to 50kHow we scaled Rudder to 10k, and the road to 50k
How we scaled Rudder to 10k, and the road to 50kRUDDER
 
What's new and what's next in Rudder
What's new and what's next in RudderWhat's new and what's next in Rudder
What's new and what's next in RudderRUDDER
 
Poss 2017 : gestion des configurations et mise en conformité chez un service ...
Poss 2017 : gestion des configurations et mise en conformité chez un service ...Poss 2017 : gestion des configurations et mise en conformité chez un service ...
Poss 2017 : gestion des configurations et mise en conformité chez un service ...RUDDER
 
Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...
Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...
Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...RUDDER
 
POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...
POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...
POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...RUDDER
 
DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...
DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...
DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...RUDDER
 
RUDDER - Continuous Configuration (configuration management + continuous aud...
 RUDDER - Continuous Configuration (configuration management + continuous aud... RUDDER - Continuous Configuration (configuration management + continuous aud...
RUDDER - Continuous Configuration (configuration management + continuous aud...RUDDER
 

Plus de RUDDER (20)

What if configuration management didn't need to be lvl60 in dev?
What if configuration management didn't need to be lvl60 in dev?What if configuration management didn't need to be lvl60 in dev?
What if configuration management didn't need to be lvl60 in dev?
 
Servers compliance: audit, remediation, proof
Servers compliance: audit, remediation, proofServers compliance: audit, remediation, proof
Servers compliance: audit, remediation, proof
 
OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?
OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?
OSIS 2019 - Qu’apporte l’observabilité à la gestion de configuration ?
 
OW2Con - Configurations, do you prove yours?
OW2Con - Configurations, do you prove yours?OW2Con - Configurations, do you prove yours?
OW2Con - Configurations, do you prove yours?
 
The new plugin ecosystem in RUDDER 5.0
The new plugin ecosystem in RUDDER 5.0The new plugin ecosystem in RUDDER 5.0
The new plugin ecosystem in RUDDER 5.0
 
What uses for observing operations of Configuration Management?
What uses for observing operations of Configuration Management?What uses for observing operations of Configuration Management?
What uses for observing operations of Configuration Management?
 
UX challenges of a UI-centric config management tool
UX challenges of a UI-centric config management toolUX challenges of a UI-centric config management tool
UX challenges of a UI-centric config management tool
 
What happened in RUDDER in 2018 and what’s next?
What happened in RUDDER in 2018 and what’s next?What happened in RUDDER in 2018 and what’s next?
What happened in RUDDER in 2018 and what’s next?
 
What is RUDDER and when should I use it?
What is RUDDER and when should I use it?What is RUDDER and when should I use it?
What is RUDDER and when should I use it?
 
Fosdem - Configurations do you prove yours?
Fosdem - Configurations  do you prove yours?Fosdem - Configurations  do you prove yours?
Fosdem - Configurations do you prove yours?
 
L'audit en continu : clé de la conformité démontrable (#POSS 2018)
L'audit en continu : clé de la conformité démontrable (#POSS 2018)L'audit en continu : clé de la conformité démontrable (#POSS 2018)
L'audit en continu : clé de la conformité démontrable (#POSS 2018)
 
Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)
Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)
Fiabilité et conformité continues en production avec Rudder (#BBOOST 2018)
 
Stay up - voyage d'un éditeur de logiciels libres
Stay up - voyage d'un éditeur de logiciels libresStay up - voyage d'un éditeur de logiciels libres
Stay up - voyage d'un éditeur de logiciels libres
 
How we scaled Rudder to 10k, and the road to 50k
How we scaled Rudder to 10k, and the road to 50kHow we scaled Rudder to 10k, and the road to 50k
How we scaled Rudder to 10k, and the road to 50k
 
What's new and what's next in Rudder
What's new and what's next in RudderWhat's new and what's next in Rudder
What's new and what's next in Rudder
 
Poss 2017 : gestion des configurations et mise en conformité chez un service ...
Poss 2017 : gestion des configurations et mise en conformité chez un service ...Poss 2017 : gestion des configurations et mise en conformité chez un service ...
Poss 2017 : gestion des configurations et mise en conformité chez un service ...
 
Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...
Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...
Poss 2017 - la continuité, arme secrète de la gestion du si - cas concret de ...
 
POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...
POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...
POSS 2017 : Comment automatiser son infrastructure quand... on a pas le temps...
 
DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...
DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...
DevOps D-Day 2017 - Gestion des configurations et mise en conformité chez un ...
 
RUDDER - Continuous Configuration (configuration management + continuous aud...
 RUDDER - Continuous Configuration (configuration management + continuous aud... RUDDER - Continuous Configuration (configuration management + continuous aud...
RUDDER - Continuous Configuration (configuration management + continuous aud...
 

Dernier

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Managing errors the right way in Scala

  • 1. 2014-10-{23,24} Managing errors the right way in Scala François ARMAND CTO - Normation far@normation.com
  • 2. Say hello ! François ARMAND far@normation.com / @fanf42 Co-founder & CTO Lead-dev Discovered Scala in 2006 OSS convinced Full time Scala since 2009 And yes, I'm trying to start a side business in cloning
  • 3. What's about ? The primary duty of an exception handler is to get the error out of the lap of the programmer and into the surprised face of the user. Provided you keep this cardinal rule in mind, you can't go far wrong. — Verity Stob Managing errors so that both futur developpers, ops and users are happy is what differentiate hacking toys projects to building softwares — Myself
  • 4. What's about ? Sharing the (hard) learned lessons about managing errors in Scala in our 5 years trip with Rudder
  • 5. What's about ? http://www.rudder-project.org IT infratructure open source automation + compliance management Server Compliance Agents Scala web application Started in 2009 By ex-java dev
  • 6. Errors ? What's an error ? Something didn't worked as it should ■ Who MUST care ? ■ Who MUST handle the problem ?
  • 7. Errors classical classification ▣ Pop culture(1) say : ▣ Technical Errors ■ When your containing universe fails □ Ex : « oups, the underlying OS just ran out of memory » □ OutOfMemroy Errors, Threads killed, VM crashes... ■ Logical / modeling error □ « no, you really can't access item #42 of that array of size 2 » ■ Systems in relation with yours failed □ Ex : « hello Database ? Helloooooo ? » □ Mostly I/O errors : connection errors, bad permession on FS... ▣ Business Errors ■ The one the user want to know about ■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » [1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
  • 8. Errors classical classification That's the end of the universe, don't care (ops will awake) ▣ Pop culture(1) say : It's complicated : ▣ Technical Errors ■ When your containing universe fails □ Ex : « oups, the underlying OS just ran out of memory » □ OutOfMemroy Errors, Threads killed, VM crashes... ■ Logical / modeling error □ « no, you really can't access item #42 of that array of size 2 » ■ Systems in relation with yours failed □ Ex : « hello Database ? Helloooooo ? » □ Mostly I/O errors : connection errors, bad permession on FS... ▣ Business Errors ■ The one the user want to know about ■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » [1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
  • 9. Errors classical classification That's the end of the universe, don't care (ops will awake) ▣ Pop culture(1) say : It's complicated : ▣ Technical Errors ■ When your containing universe fails □ Ex : « oups, the underlying OS just ran out of memory » □ OutOfMemroy Errors, Threads killed, VM crashes... ■ Logical / modeling error That should be modeled in data type □ « no, you really can't access item #42 of that array of size 2 » ■ Systems in relation with yours failed □ Ex : « hello Database ? Helloooooo ? » □ Mostly I/O errors : connection errors, bad permession on FS... ▣ Business Errors ■ The one the user want to know about ■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » [1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
  • 10. Errors classical classification That's the end of the universe, don't care (ops will awake) ▣ Pop culture(1) say : It's complicated : ▣ Technical Errors ■ When your containing universe fails □ Ex : « oups, the underlying OS just ran out of memory » □ OutOfMemroy Errors, Threads killed, VM crashes... ■ Logical / modeling error That should be modeled in data type □ « no, you really can't access item #42 of that array of size 2 » ■ Systems in relation with yours failed Always the business □ Ex : « hello Database ? Helloooooo ? » □ Mostly I/O errors : connection errors, bad permession on FS... ▣ Business Errors of somebody : dev, ops, final user ■ The one the user want to know about ■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » [1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
  • 11. Errors classical classification That's the end of the universe, don't care (ops will awake) ▣ Pop culture(1) say : It's complicated : ▣ Technical Errors ■ When your containing universe fails □ Ex : « oups, the underlying OS just ran out of memory » □ OutOfMemroy Errors, Threads killed, VM crashes... ■ Logical / modeling error That should be modeled in data type □ « no, you really can't access item #42 of that array of size 2 » ■ Systems in relation with yours failed Always the business □ Ex : « hello Database ? Helloooooo ? » □ Mostly I/O errors : connection errors, bad permession on FS... ▣ Business Errors of somebody : dev, ops, final user ■ The one the user want to know about ■ Ex : « oups, I can't withdraw $1M from your empty account, because, well, you know » [1] http://programmer.97things.oreilly.com/wiki/index.php/Distinguish_Business_Exceptions_from_Technical
  • 12. So, what was our trip in error management land ?
  • 13. Origins : the dark age of Java Exceptions ▣ Using Java Exception ■ Worst : Business and Technical Exception, enterprisy style
  • 14. Origins : the dark age of Java Exceptions Problems ? ▣ Death by one thousand different GoTos ▣ Can't reason about part of the code ■ Hard to understand ■ Hard to compose ■ Hard to refactor ■ Hard to reuse ▣ Exception are the incarnation of side effect Error management must be referentially transparent
  • 15. Origins : the dark age of Java Exceptions Problems ? ▣ Dilution of responsability ■ Nobody ever manage exception in a systematic way ■ Idem in language with error code (C, Python, Go...) ▣ Human being are not very disciplined ■ That why we automate things
  • 16. Origins : the dark age of Java Exceptions Problems ? ▣ Human being are not very disciplined ▣ But hey ! Compilers DO ARE very disciplined ▣ Crazy idea: ■ Force the user to take care of failure to reach success values ■ Use a data type denoting Error Or Success ▣ Nice side effects: ■ Clear identification function that could fail in return type ■ Errors as value enable referential transparency Model faillible code with Algebraic Data Type
  • 17. Origins : the dark age of Java Exceptions Exception: far better tools exists (in Scala)
  • 18. Option to the rescue (really?) ▣ Functionnal programming 101 : use option ■ Option[+A] □ None □ Some[+A](x: A) Need a rich failure type
  • 19. Option – just to denote missing things Option : good data type. Not for error. Its semantic is « MISSING ITEM »
  • 20. Either to the rescue (ok, still no) ▣ Functionnal programming 101, page 2 : use disjunction Either[L,R] : Left[L] : failure and Right[R] : success But....
  • 21. Either to the rescue (ok, still no) ▣ Functionnal programming 101, page 2 : use disjunction Either[L,R] : Left[L] : failure and Right[R] : success ??? Ticket #SI-5793, close won't fix No boilerplate !
  • 22. Either – for the boilerplate lovers Either (Scala stdlib): not tailored for errors
  • 23. Nice try ▣ Try[A] – essentially an Either[Throwable, A] ■ Nice on paper (not used in real life) □ Even with theoric hole (see « Try and monad laws ») ■ But really ? Everything is an exception ? Need a rich failure type
  • 24. Try – when all your errors are exception Try: NOT ALL errors are exceptions Oh, and what could go wrong with ignoring theory ?
  • 25. A Lift gift in a Box ▣ Lift, that new web framework (2009 style) ▣ Box[T] : data structure with 3 cases : ■ Full[+A](value: A) extends Box[A] □ a success that hold your item of type T ■ EmptyBox extends Box[Nothing] (abstract) □ Empty : no results (None for Option) extends EmptyBox □ Failure(msg: String, exception: Box[Throwable] , chain: Box[Failure]) extends EmptyBox
  • 26. A Lift gift in a Box
  • 27. A Lift gift in a Box – with error tooling !
  • 28. A Lift gift in a Box – with error tooling ! Tooling and error lexical field helps
  • 29. A Lift gift in a Box – with error tooling ! But....
  • 30. So bad it was offered by Pandora ▣ getUser(User("fanf42")) === Empty. ■ What do you thing it means ? ■ Depending of the dev, the refactorer, the tests, it's an error without message. ■ Or a missing item. ▣ In Rudder, the most surprising error where due to Empty ■ Surprise is a bad thing: Empty is forbidden. ■ Object DB { def getUser(id : UserId) : Box[Option[User]] } Must be Unambiguious
  • 31. (Pandora) Box might have been good Box: good tooling, too much ambiguity
  • 32. Finally, let's go shopping ? So, no error management framework ?
  • 33. Desirable properties of error management Error management must be referentially transparent Model faillible code with Algebraic Data Type Must be Unambiguious Need a rich failure type No boilerplate ! Tooling and error lexical field helps
  • 34. It's a kind of magic ▣ You know what ? People worked on theory about that. ■ Theory-backed model free you mind : you know it WILL work. It's proved ■ http://typelevel.org/blog/2014/02/21/error-handling.html ■ http://stackoverflow.com/questions/12307965/method-parameters-validation-in-scala- with-for-comprehension-and-monads/12309023#12309023
  • 35. Theory says Independant Errors Dependant Errors ▣ Form validation ▣ Accumulate them ▣ « best-effort » ▣ List of I/O actions ▣ Chain them ▣ Stop early Scalaz.Validation (applicative functor) Scalaz./ (monad)
  • 36. Independant Errors ▣ Form validation ▣ Accumulate them ▣ « best-effort » Theory says Scalaz.Validation (applicative functor)
  • 37. Scalaz.Validation – accumulating errrors ▣ It's an applicative functor : no for-comprehension
  • 38. Theory says Dependant Errors ▣ List of I/O actions ▣ Chain them ▣ Stop early Scalaz./ (monad)
  • 39. Scalaz disjunction – a sane Either
  • 40. So, no shopping after all ? ▣ Validation is great for applicative style failure. ■ It's more generic / less powerful ■ In fact only used in very specific cases ▣ / is great for general error management ■ Toward monadic application ▣ But...
  • 41. Tooling on top of / (and Validation) ▣ Nothing in / is in the semantic domain of errors. ▣ And it's desirable to have : ■ One default generic Failure data structure ■ With tooling (message, root cause, etc) ■ À la Box. ▣ Some leads to follow : ■ Design your own Failure with sugar to add messages / Throwable ■ User library extension with implicit to add more sugar What follows are JUST ideas and example
  • 42. Tooling on top of / (and Validation) A dedicated Fail data type
  • 43. Tooling on top of / (and Validation) A dedicated Error data type
  • 44. Tooling on top of / (and Validation)
  • 45. Tooling on top of / (and Validation)
  • 46. 2014-10-{23,24} Questions ? François ARMAND far@normation.com / @fanf42 Code available on GitHub : https://github.com/fanf/scalaio_2014