Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha next #44

Merged
merged 13 commits into from
Apr 29, 2020
Prev Previous commit
Next Next commit
feat: throw human readable error when budget file format is not suppo…
…rted
  • Loading branch information
Xiphe committed Apr 28, 2020
commit 825fd54cccaf2d920adeb39e107d1a42a1d27729
10 changes: 10 additions & 0 deletions src/budget/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export type IncomeCategory = t.TypeOf<typeof incomeCategoryShape>;
export type Settings = t.TypeOf<typeof settingsShape>;

export function validateBudgetState(data: unknown): BudgetState {
if (typeof data !== 'object' || data === null) {
throw new Error('Invalid budget file format');
}
const version: unknown = (data as any).version;
if (!version || version === '0.0.1') {
throw new Error(
'File format not supported. Please use an earlier version of BudgetBudget to open this file',
);
}

const c = budgetStateShape.decode(data);
if (isLeft(c)) {
throw ThrowReporter.report(c);
Expand Down