Skip to content

Commit

Permalink
fix(config): throw error early if tools/template resolution fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Dec 16, 2022
1 parent 401f08a commit 2f2e467
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/sanity/src/core/config/__tests__/resolveConfig.test.ts
Expand Up @@ -5,6 +5,22 @@ import {createMockAuthStore} from '../../store'
import {resolveConfig, createWorkspaceFromConfig, createSourceFromConfig} from '../resolveConfig'

describe('resolveConfig', () => {
it('throws on invalid tools property', async () => {
expect.assertions(1)
try {
await resolveConfig({
projectId: 'ppsg7ml5',
dataset: 'production',
// @ts-expect-error should be an array
tools: {},
})
.pipe(first())
.toPromise()
} catch (err) {
expect(err.message).toMatch('Expected `tools` to an array or a function but found object')
}
})

it('returns an observable that emits an array of fully resolved workspaces', async () => {
const projectId = 'ppsg7ml5'
const dataset = 'production'
Expand Down
13 changes: 10 additions & 3 deletions packages/sanity/src/core/config/prepareConfig.ts
Expand Up @@ -284,7 +284,11 @@ function resolveSource({
// TODO: validate templates
// TODO: validate that each one has a unique template ID
} catch (e) {
errors.push(e)
throw new ConfigResolutionError({
name: config.name,
type: 'source',
causes: [e],
})
}

let tools!: Source['tools']
Expand All @@ -297,7 +301,11 @@ function resolveSource({
reducer: toolsReducer,
})
} catch (e) {
errors.push(e)
throw new ConfigResolutionError({
name: config.name,
type: 'source',
causes: [e],
})
}

// In this case we want to throw an error because it is not possible to have
Expand Down Expand Up @@ -344,7 +352,6 @@ function resolveSource({
if (templateErrors.length) {
throw new ConfigResolutionError({
name: config.name,
// TODO: figure out this name
type: 'source',
causes: templateErrors,
})
Expand Down

1 comment on commit 2f2e467

@vercel
Copy link

@vercel vercel bot commented on 2f2e467 Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.