diff --git a/json.wake b/json.wake index 0a77b6e..878ebdb 100644 --- a/json.wake +++ b/json.wake @@ -1,7 +1,7 @@ package json from wake import _ -from utils import prefixError +from result import prefixError from query import _ # Anyone who depends on json will also diff --git a/result.wake b/result.wake new file mode 100644 index 0000000..fd6e5fe --- /dev/null +++ b/result.wake @@ -0,0 +1,17 @@ +package result + +# When `result` is Fail, prefixes the internal error message with `prefix` +# +# Parameters: +# - `prefix`: The message to prepend to `result` +# - `result`: The Result which may be prepended to +# +# Examples: +# ``` +# prefixError "foo" (Pass 123) -> Pass 123 +# prefixError "foo" (Fail (Error "bar" stack)) => Fail (Error "foobar" stack) +# ``` +export def prefixError (prefix: String): (result: Result a Error) => Result a Error = match _ + Pass r -> Pass r + Fail (Error msg stack) -> Fail (Error "{prefix}{msg}" stack) +