SlideShare a Scribd company logo
1 of 46
Download to read offline
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

More Related Content

Viewers also liked

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
 

Viewers also liked (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
 

More from 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
 

More from 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...
 

Recently uploaded

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

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