gajus / gajus/flow-runtime

Converting a type validation to an error string

Open
#121 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
797
Forks
49
PR merge metrics
No merged PRs in 30d

Description

This is a:

- [ ] Bug Report
- [x] Feature Request
- [ ] Question
- [ ] Other

Which concerns:

- [x] flow-runtime
- [ ] babel-plugin-flow-runtime
- [ ] flow-runtime-validators
- [ ] flow-runtime-mobx
- [ ] flow-config-parser
- [ ] The documentation website

---

### What is the current behaviour?

There doesn't seem to be an API to get the validation error message as a string (to handle it in a custom way).

---

### What is the expected behaviour?

There should be :)

Our use case for flow-runtime is generating validation code from a flow type declaration, and running that against data that a backend sends us. We'd like to have the default formatted message, but handle it in a custom way (i.e. not simple console.warn). For now I've settled on this hacky-as-hell way:

```js
let message; // hack (flow-runtime has no API to get the message as a string)
flowRuntime.emitWarningMessage = m => message = m;

... // inside an Express controller:
message = null;
flowRuntime.warn(type, value);
if (message) {
// do useful stuff here, i.e:
req.logger.log(message);
}

```

Ideally, there should be something akin to the current `t.makeJSONError(validation)`, say `t.makeFormattedMessage(validation)`.

This issue is a more general version of https://github.com/codemix/flow-runtime/issues/99

---

### Which package versions are you using?

0.12.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.