From 89e9fd59bb7487d55281b8c4d5543a1a2705aa0a Mon Sep 17 00:00:00 2001 From: Marc Mignonsin Date: Thu, 21 Nov 2024 17:24:06 +0100 Subject: [PATCH 1/3] SceneVariableSet: Store the whole error object instead of the error message --- .../src/variables/sets/SceneVariableSet.test.tsx | 12 ++++++------ .../scenes/src/variables/sets/SceneVariableSet.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/scenes/src/variables/sets/SceneVariableSet.test.tsx b/packages/scenes/src/variables/sets/SceneVariableSet.test.tsx index 29d5da027..a5a582030 100644 --- a/packages/scenes/src/variables/sets/SceneVariableSet.test.tsx +++ b/packages/scenes/src/variables/sets/SceneVariableSet.test.tsx @@ -629,7 +629,7 @@ describe('SceneVariableList', () => { scene.activate(); - expect(A.state.error).toBe('Danger!'); + expect(A.state.error).toStrictEqual(new Error('Danger!')); }); it('Should complete updating chained variables in case of error in all variables', () => { @@ -665,11 +665,11 @@ describe('SceneVariableList', () => { scene.activate(); expect(A.state.loading).toBe(false); - expect(A.state.error).toBe('Error in A'); + expect(A.state.error).toStrictEqual(new Error('Error in A')); expect(B.state.loading).toBe(false); - expect(B.state.error).toBe('Error in B'); + expect(B.state.error).toStrictEqual(new Error('Error in B')); expect(C.state.loading).toBe(false); - expect(C.state.error).toBe('Error in C'); + expect(C.state.error).toStrictEqual(new Error('Error in C')); }); it('Should complete updating chained variables in case of error in the first variable', () => { const A = new TestVariable({ @@ -702,7 +702,7 @@ describe('SceneVariableList', () => { scene.activate(); expect(A.state.loading).toBe(false); - expect(A.state.error).toBe('Error in A'); + expect(A.state.error).toStrictEqual(new Error('Error in A')); B.signalUpdateCompleted(); expect(B.state.loading).toBe(false); @@ -750,7 +750,7 @@ describe('SceneVariableList', () => { expect(B.state.loading).toBe(false); expect(B.state.value).toBe(''); - expect(B.state.error).toBe('Error in B'); + expect(B.state.error).toStrictEqual(new Error('Error in B')); C.signalUpdateCompleted(); expect(C.state.loading).toBe(false); diff --git a/packages/scenes/src/variables/sets/SceneVariableSet.ts b/packages/scenes/src/variables/sets/SceneVariableSet.ts index b95efb7f7..aed845499 100644 --- a/packages/scenes/src/variables/sets/SceneVariableSet.ts +++ b/packages/scenes/src/variables/sets/SceneVariableSet.ts @@ -247,7 +247,7 @@ export class SceneVariableSet extends SceneObjectBase imp this._updating.delete(variable); this._variablesToUpdate.delete(variable); - variable.setState({ loading: false, error: err.message }); + variable.setState({ loading: false, error: err }); console.error('SceneVariableSet updateAndValidate error', err); From 6ff3f8b8f9fb48f82c0d85334bb76918c5163314 Mon Sep 17 00:00:00 2001 From: Marc Mignonsin Date: Wed, 27 Nov 2024 12:21:32 +0100 Subject: [PATCH 2/3] fix(VariableValueSelectors): Check error type before display --- .../scenes/src/variables/components/VariableValueSelectors.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scenes/src/variables/components/VariableValueSelectors.tsx b/packages/scenes/src/variables/components/VariableValueSelectors.tsx index 22838d854..a125e0d71 100644 --- a/packages/scenes/src/variables/components/VariableValueSelectors.tsx +++ b/packages/scenes/src/variables/components/VariableValueSelectors.tsx @@ -79,7 +79,7 @@ function VariableLabel({ variable, layout, hideLabel }: VariableSelectProps) { isLoading={state.loading} onCancel={() => variable.onCancel?.()} label={labelOrName} - error={state.error} + error={typeof state.error === 'object' ? state.error.message : state.error} layout={layout} description={state.description ?? undefined} /> From b1b43b285b0936868ab3fc1dfe57f83af1e9a56e Mon Sep 17 00:00:00 2001 From: Marc Mignonsin Date: Wed, 27 Nov 2024 12:36:46 +0100 Subject: [PATCH 3/3] fix: Account for null case --- .../scenes/src/variables/components/VariableValueSelectors.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scenes/src/variables/components/VariableValueSelectors.tsx b/packages/scenes/src/variables/components/VariableValueSelectors.tsx index a125e0d71..305ccd2f3 100644 --- a/packages/scenes/src/variables/components/VariableValueSelectors.tsx +++ b/packages/scenes/src/variables/components/VariableValueSelectors.tsx @@ -79,7 +79,7 @@ function VariableLabel({ variable, layout, hideLabel }: VariableSelectProps) { isLoading={state.loading} onCancel={() => variable.onCancel?.()} label={labelOrName} - error={typeof state.error === 'object' ? state.error.message : state.error} + error={state.error?.message || state.error} layout={layout} description={state.description ?? undefined} />