Giter Site home page Giter Site logo

Comments (3)

snoyberg avatar snoyberg commented on September 14, 2024

sendMailCustom isn't partial, it throws an exception when something exceptional occurs. This is standard practice in Haskell across many libraries, including base (take readFile, for instance). I am in favor of improving this package so that it throws a proper exception type instead of using error. But exception usage in Haskell is pervasive. If you want to change that, it's a far bigger task than adding a function to this package.

from mime-mail.

ocharles avatar ocharles commented on September 14, 2024

Ok, so it's not partial by a strict "over-all-input" definition, but still the function can evaluate to ⊥ which is more the problem I'm getting at. I'm aware that this is the current general practice in Haskell, but I don't think that's a reason we can't offer a non-throwing version (perhaps alongside one that does throw). I'm not looking like to change how all of Haskell works, though when I encounter problems where I would prefer a real error type, I do raise tickets :)

from mime-mail.

snoyberg avatar snoyberg commented on September 14, 2024

Nope, it can't:

{-# LANGUAGE BangPatterns #-}
import Control.Exception
import Network.Mail.Mime

main :: IO ()
main = do
    _ <- evaluate $ sendmail undefined
    putStrLn "Not partial"
    !_ <- evaluate $ sendmail undefined
    putStrLn "Still not partial"
    _ <- evaluate undefined
    putStrLn "Yep, that's partial"

Part of the contract of IO is that it can throw exceptions. sendmail itself will throw an exception if the sendmail process returns an failure exit code. But that's not the only way. Consider this seemingly safe code:

import Network.Mail.Mime
import Data.ByteString.Lazy.Char8 (pack)

main :: IO ()
main = sendmail $ pack "To: [email protected]\r\nSubject: test\r\n\r\nThis is a test"

Run it on a system without the sendmail executable, and you get:

foo.hs: fd:9: hClose: resource vanished (Broken pipe)

There are many other things that can go wrong: incorrect permissions, too many open file handles, etc.

In other words: no matter what you need to take exceptions into account. Changing the sendmail function's behavior won't change the fact that you're in IO, and you have to respect the contract that it might throw an exception. Making this change would imply something which isn't true.

from mime-mail.

Related Issues (20)

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.