Skip to content

Commit

Permalink
Fix error messages when importing .keystone/config.js (#9359)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com>
  • Loading branch information
marekryb and dcousens authored Oct 15, 2024
1 parent 7b90efb commit 70eaf68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-files-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fix misleading error messages when importing `.keystone/config.js`
14 changes: 6 additions & 8 deletions packages/core/src/scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getBuiltKeystoneConfigurationPath } from '../lib/createSystem'
import fs from 'node:fs/promises'

export class ExitError extends Error {
code: number
Expand All @@ -10,13 +11,10 @@ export class ExitError extends Error {

// TODO: this cannot be changed for now, circular dependency with getSystemPaths, getEsbuildConfig
export async function importBuiltKeystoneConfiguration (cwd: string) {
try {
return require(getBuiltKeystoneConfigurationPath(cwd)).default
} catch (err: any) {
if (err.code === 'MODULE_NOT_FOUND') {
console.error('🚨 keystone build has not been run')
throw new ExitError(1)
}
throw err
const builtConfigPath = getBuiltKeystoneConfigurationPath(cwd)
if (!(await fs.stat(builtConfigPath).catch(() => null))) {
console.error('🚨 keystone build has not been run')
throw new ExitError(1)
}
return require(builtConfigPath).default
}

0 comments on commit 70eaf68

Please sign in to comment.