Skip to main content

Debugging

$Flow$DebugPrint, $Flow$DebugThrow, $Flow$DebugSleep​

Throw and sleep are not very useful in normal code. Throw kills Flow and sleep adds delay in seconds. More useful is debug print which prints debug information:

// @flow strict
const x = 10;
declare var flowDebugPrint: $Flow$DebugPrint;
flowDebugPrint(x);

Output:

πŸ’ƒ universe [master] y flow
yarn run v1.16.0
$ /Users/mrtnzlml/Work/kiwi-private/incubator/universe/node_modules/.bin/flow
Error β”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆ src/test.js:4:1

{
"reason":{
"pos":{
"source":"/Users/mrtnzlml/Work/kiwi-private/incubator/universe/src/test.js",

"type":"SourceFile",
"start":{"line":4,"column":16},
"end":{"line":4,"column":16}
},

"desc":"number"
},
"kind":"NumT",
"literal":"10"
}

1β”‚ // @flow strict
2β”‚ const x = 10;
3β”‚ declare var flowDebugPrint: $Flow$DebugPrint;
4β”‚ flowDebugPrint(x);
5β”‚



Found 1 error

Advanced debugging​

yarn flow errors may be sometimes very cryptic:

Error β”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆ src/apps/autobooking/queries/Autobooking.js:27:26

Cannot call await with context.dataLoaders.autobooking.getResult(...) bound to p because property autobooking is missing
in Promise [1].

src/apps/autobooking/queries/Autobooking.js
24β”‚ { bid }: argsType,
25β”‚ context: GraphqlContextType
26β”‚ ): Promise<AutobookingType> => {
27β”‚ const result = await context.dataLoaders.autobooking.getResult(bid)
28β”‚ const { autobooking, status } = result
29β”‚
30β”‚ if (autobooking === null) {

src/apps/autobooking/Datasource.js
[1] 19β”‚ ): Promise<{|
20β”‚ +autobooking: Autobooking | null,
21β”‚ +status: string
22β”‚ |}> {

It helps to inspect the whole stacktrace using yarn flow --show-all-branches:

Error β”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆ src/apps/autobooking/queries/Autobooking.js:27:26

Cannot call await with context.dataLoaders.autobooking.getResult(...) bound to p because:
β€’ Either cannot return object literal because in property status of type argument R [1]:
β€’ Either string [2] is incompatible with string literal pending [3].
β€’ Or string [2] is incompatible with string literal check_failed [4].
β€’ Or string [2] is incompatible with string literal ready [5].
β€’ Or string [2] is incompatible with string literal started [6].
β€’ Or string [2] is incompatible with string literal too_expensive [7].
β€’ Or property autobooking is missing in Promise [8].

src/apps/autobooking/queries/Autobooking.js
24β”‚ { bid }: argsType,
25β”‚ context: GraphqlContextType
26β”‚ ): Promise<AutobookingType> => {
27β”‚ const result = await context.dataLoaders.autobooking.getResult(bid)
28β”‚ const { autobooking, status } = result
29β”‚
30β”‚ if (autobooking === null) {

/private/tmp/flow/flowlib_2c621631/core.js
[1] 583β”‚ declare class Promise<+R> {

src/apps/autobooking/Datasource.js
[8] 19β”‚ ): Promise<{|
20β”‚ +autobooking: Autobooking | null,
[2] 21β”‚ +status: string
22β”‚ |}> {

src/apps/autobooking/apiTypes/Autobooking.js
[3][4][5][6][7] 7β”‚ status: 'pending' | 'check_failed' | 'ready' | 'started' | 'too_expensive'

You can eventually use yarn flow check --traces 100