Skip to content

Commit

Permalink
take ai feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Jan 31, 2025
1 parent f07a764 commit a3493be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/web/app/src/lib/hooks/use-local-storage-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ export function useLocalStorageJson<$Schema extends z.ZodType>(...args: ArgsInpu
// - Let caller choose an error strategy: 'return' / 'default' / 'throw'
try {
return schema.parse(JSON.parse(storedValue));
} catch (_) {
} catch (error) {
if (error instanceof SyntaxError) {
console.warn(`useLocalStorageJson: JSON parsing failed for key "${key}"`, error);
} else if (error instanceof z.ZodError) {
console.warn(`useLocalStorageJson: Schema validation failed for key "${key}"`, error);
} else {
Kit.neverCatch(error);
}
return defaultValue;
}
});
Expand Down
10 changes: 9 additions & 1 deletion packages/web/app/src/lib/kit/never.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/**
* This case of thrown value is impossible.
* If it happens, then that means there is a defect in our code.
*/
export const neverCatch = (value: unknown): never => {
never({ type: 'catch', value });
};

/**
* This case is impossible.
* If it happens, then that means there is a bug in our code.
* If it happens, then that means there is a defect in our code.
*/
export const neverCase = (value: never): never => {
never({ type: 'case', value });
Expand Down

0 comments on commit a3493be

Please sign in to comment.