Skip to content

Commit

Permalink
fix(errors): Add missing swallowError call, plus debugging URL (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Sep 22, 2018
1 parent 8f3c0e7 commit bc66c8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
19 changes: 2 additions & 17 deletions packages/graphile-build-pg/src/plugins/PgQueryProceduresPlugin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @flow
import type { Plugin } from "graphile-build";
import debugFactory from "debug";
import chalk from "chalk";

const debugWarn = debugFactory("graphile-build-pg:warn");

export default (function PgQueryProceduresPlugin(
builder,
Expand All @@ -21,6 +17,7 @@ export default (function PgQueryProceduresPlugin(
pgOmit: omit,
describePgEntity,
sqlCommentByAddingTags,
swallowError,
} = build;
const {
scope: { isRootQuery },
Expand Down Expand Up @@ -96,19 +93,7 @@ export default (function PgQueryProceduresPlugin(
)}`
);
} catch (e) {
// eslint-disable-next-line no-console
console.warn(
chalk.bold.yellow(
`Failed to add function '${proc.namespace.name}.${
proc.name
}'${
debugWarn.enabled
? ""
: `; run with 'DEBUG="graphile-build-pg:warn"' to view the error`
}`
)
);
debugWarn(e);
swallowError(e);
}
}
if (!proc.returnsSet || hasConnections) {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphile-build/src/swallowError.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export default function swallowError(e: Error): void {
if (errorSnippet) {
// eslint-disable-next-line no-console
console.warn(
`Recoverable error occurred; use envvar 'DEBUG="graphile-build:warn"' for full error\n> ${errorSnippet}…`
`Recoverable error occurred; use envvar 'DEBUG="graphile-build:warn"' for full error (see: http://graphile.org/postgraphile/debugging )\n> ${errorSnippet}…`
);
} else {
// eslint-disable-next-line no-console
console.warn(
`Recoverable error occurred; use envvar 'DEBUG="graphile-build:warn"' for error`
`Recoverable error occurred; use envvar 'DEBUG="graphile-build:warn"' for error (see: http://graphile.org/postgraphile/debugging )`
);
}
debugWarn(e);
Expand Down
10 changes: 8 additions & 2 deletions packages/postgraphile-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,13 @@ const getPostGraphileBuilder = async (
}
});
});
memoizeCache = JSON.parse(cacheString);
try {
memoizeCache = JSON.parse(cacheString);
} catch (e) {
throw new Error(
`Failed to parse cache file '${readCache}', perhaps it is corrupted? ${e}`
);
}
}
if (readCache || writeCache) {
persistentMemoizeWithKey = (key: string, fn: () => any) => {
Expand Down Expand Up @@ -348,7 +354,7 @@ export const createPostGraphileSchema = async (
});
const schema = builder.buildSchema();
if (writeCache) {
writeCache().catch(abort);
await writeCache().catch(abort);
}
return schema;
};
Expand Down

0 comments on commit bc66c8f

Please sign in to comment.