fp-ts-local-storage icon indicating copy to clipboard operation
fp-ts-local-storage copied to clipboard

All local storage interactions are unsafe

Open samhh opened this issue 4 years ago • 2 comments

Per here, local storage can throw for many reasons, for example - something a project of mine has been bitten by before - the user having disabled it in their browser.

With this in mind, all of the APIs in this library are currently deceptively unsafe. Some options:

  1. Add documentation alluding to this unsafety
  2. Add new safe variants, and prefix the preexisting ones with unsafe
  3. Rewrite everything to be safe - presumably using E.tryCatch under the hood and asking for an error handler from the user - e.g. number -> IO<Option<string>> becomes (unknown -> E) -> number -> IO<Either<E, Option<string>>>

samhh avatar Apr 07 '20 15:04 samhh

I think that a solution could be use IOEither and release a new major version of the library

StefanoMagrassi avatar Apr 08 '20 07:04 StefanoMagrassi

Thanks @SamHH

Add documentation alluding to this unsafety

This is a good first step.

gcanti avatar Apr 08 '20 09:04 gcanti