From 2f2e4678aadb4ef46f2d12f8c288b6ba73f5e98b Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Wed, 14 Dec 2022 11:51:31 -0800 Subject: [PATCH] fix(config): throw error early if tools/template resolution fails --- .../core/config/__tests__/resolveConfig.test.ts | 16 ++++++++++++++++ packages/sanity/src/core/config/prepareConfig.ts | 13 ++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/core/config/__tests__/resolveConfig.test.ts b/packages/sanity/src/core/config/__tests__/resolveConfig.test.ts index 7f1bca2dbdd..f218fe5e064 100644 --- a/packages/sanity/src/core/config/__tests__/resolveConfig.test.ts +++ b/packages/sanity/src/core/config/__tests__/resolveConfig.test.ts @@ -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' diff --git a/packages/sanity/src/core/config/prepareConfig.ts b/packages/sanity/src/core/config/prepareConfig.ts index fc2456d4ece..fd041169083 100644 --- a/packages/sanity/src/core/config/prepareConfig.ts +++ b/packages/sanity/src/core/config/prepareConfig.ts @@ -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'] @@ -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 @@ -344,7 +352,6 @@ function resolveSource({ if (templateErrors.length) { throw new ConfigResolutionError({ name: config.name, - // TODO: figure out this name type: 'source', causes: templateErrors, })