Coder Social home page Coder Social logo

clarify-exception-refactoring-kata's Introduction

Clarify Exception Refactoring Kata

This is a refactoring exercise starting point. Focus on improving the code in the MessageEnricher class.

Note there is a branch 'with_tests' if you'd like to go straight to doing the refactoring and skip writing tests yourself.

This exercise has similar features to some code I worked on when I was coaching a team. We could all see there was some duplication and a long method smell, but it took some time to work out how to improve it. I made this exercise as a way to enable us all to practice what to do if this kind of thing happens again.

The Scenario

You are working on an application for tax calculations. Your users upload a spreadsheet containing some formulas, lookup tables, and raw data. Your software reads the spreadsheet and processes it using a proprietary library. If the user has made any mistakes in their spreadsheet, the proprietary library produces an exception. These exceptions are quite hard for the user to interpret. This piece of code that you have here, is designed to clarify the exception. The 'enrichError' method is responsible for doing this. It will take the exception produced by the proprietary library, and return it to the user as an "ErrorResult" with an enriched message that they will hopefully understand.

You can change the code and improve it, but don't change the signature of the 'enrichError' method. The rest of the system (not included here) relies on it.

The New Feature

The users have come to you complaining they don't understand when they get the message "Missing Formula", when they are sure the formula is not missing. You identify that this happens when the proprietary spreadsheet library has thrown a SpreadsheetException because some cells are merged that shouldn't be merged. The clarified message the user would like to see is:

"Invalid expression found in tax formula [" + formulaName +
                        "]. Check for merged cells near " + cells;

(The formulaName in the above message is one of the input parameters to the method for enriching the error message, and the cells are the ones held as a datamember in the SpreadsheetException.)

Your task is to refactor the code to make adding this new feature as easy as possible. The finished code including the new feature should be easy to maintain for subsequent developers, and contain minimal duplication.

clarify-exception-refactoring-kata's People

Contributors

boucardbruno avatar codecop avatar emilybache avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.