joelnet / MojiScript

MojiScript is an async-first, opinionated, and functional library

Home Page:https://mojiscript.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tap should not swallow async errors

joelnet opened this issue · comments

Expected behavior is to bubble up exceptions.

Incorrect:

import pipe from 'mojiscript/core/pipe'
import tap from 'mojiscript/function/tap'

const oops = () => Promise.reject (Error ('OOPS'))

const main = ({ log }) => pipe ([
  'Hello World',
  tap (oops),
  log
])

export default main
//=> 'Hello World'

Correct:

import pipe from 'mojiscript/core/pipe'
import tap from 'mojiscript/function/tap'

const oops = () => { throw Error ('OOPS')}

const main = ({ log }) => pipe ([
  'Hello World',
  tap (oops),
  log
])

export default main
//=> Error: OOPS
    at oops (file:///Users/jthoms/dev/mojiscript-starter-app/src/main.mjs:4:28)
    at x (/Users/jthoms/dev/mojiscript-starter-app/node_modules/mojiscript/combinators/S.js:1:95)