From 0ffcff2a4cfe2d92b6f11002a85d5056ebb26a8f Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Mon, 13 Feb 2023 22:27:24 -0800 Subject: [PATCH] chore: fix types for compile issue --- libs/environment/src/hooks/use-environment.ts | 3 ++- libs/environment/src/utils/compile-errors.ts | 19 ++++++++++++++----- .../src/utils/validate-environment.ts | 6 +----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/environment/src/hooks/use-environment.ts b/libs/environment/src/hooks/use-environment.ts index 8b468b530..483f67733 100644 --- a/libs/environment/src/hooks/use-environment.ts +++ b/libs/environment/src/hooks/use-environment.ts @@ -87,7 +87,8 @@ export const useEnvironment = create((set, get) => ({ const rawVars = compileEnvVars(); const safeVars = EnvSchema.parse(rawVars); set({ ...safeVars }); - } catch (err) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (err: any) { set({ status: 'failed', error: t('Error processing the Vega environemnt'), diff --git a/libs/environment/src/utils/compile-errors.ts b/libs/environment/src/utils/compile-errors.ts index 401b156a1..11e533b80 100644 --- a/libs/environment/src/utils/compile-errors.ts +++ b/libs/environment/src/utils/compile-errors.ts @@ -1,9 +1,18 @@ -import type { ZodIssue, ZodError } from 'zod'; +import type { ZodIssue } from 'zod'; +import { ZodError } from 'zod'; -export const compileErrors = (headline: string, error: ZodError) => { - return error.issues.reduce((acc, issue) => { - return acc + `\n - ${compileIssue(issue)}`; - }, headline); +export const compileErrors = ( + headline: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error: any +) => { + if (error instanceof ZodError) { + return error.issues.reduce((acc, issue) => { + return acc + `\n - ${compileIssue(issue)}`; + }, headline); + } + + return `${headline}${error?.message ? `: ${error.message}` : ''}`; }; const compileIssue = (issue: ZodIssue) => { diff --git a/libs/environment/src/utils/validate-environment.ts b/libs/environment/src/utils/validate-environment.ts index 7f2b506fb..c688535e9 100644 --- a/libs/environment/src/utils/validate-environment.ts +++ b/libs/environment/src/utils/validate-environment.ts @@ -89,10 +89,6 @@ export const validateEnvironment = ( return undefined; // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { - return compileErrors( - 'Error processing the vega app environment', - err, - compileIssue - ); + return compileErrors('Error processing the vega app environment', err); } };