Skip to content

Commit

Permalink
refactor: replace assert statements with error handling in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Jan 3, 2025
1 parent 791ee89 commit 9fe2983
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
14 changes: 7 additions & 7 deletions scripts/build-docs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import lodash from 'lodash';

import type { NavTree, NavTreeItem, RecursiveChildren } from '@/types/scripts/build-docs';
Expand Down Expand Up @@ -106,8 +105,11 @@ function buildNavTree(navItems: Details[]) {

return tree;
} catch (err) {
assert(err instanceof Error);
throw new Error(`Failed to build navigation tree: ${err.message}`);
if (err instanceof Error) {
throw new Error(`Failed to build navigation tree: ${err.message}`);
} else {
throw new Error(`Failed to build navigation tree: ${err}`);

Check warning on line 111 in scripts/build-docs.ts

View check run for this annotation

Codecov / codecov/patch

scripts/build-docs.ts#L111

Added line #L111 was not covered by tests
}
}
}

Expand All @@ -132,8 +134,7 @@ const convertDocPosts = (docObject: NavTree | Details) => {

return docsArray;
} catch (err) {
assert(err instanceof Error);
throw new Error('Error in convertDocPosts:', err);
throw new Error('Error in convertDocPosts:', err as Error);
}
};

Expand Down Expand Up @@ -218,8 +219,7 @@ function addDocButtons(docPosts: Details[], treePosts: NavTree) {
return docPost;
});
} catch (err) {
assert(err instanceof Error);
throw new Error('An error occurred while adding doc buttons:', err);
throw new Error('An error occurred while adding doc buttons:', err as Error);
}

return structuredPosts;
Expand Down
8 changes: 5 additions & 3 deletions scripts/build-meetings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { writeFileSync } from 'fs';
import { google } from 'googleapis';
import { dirname, resolve } from 'path';
Expand All @@ -19,8 +18,11 @@ async function buildMeetings(writePath: string) {

calendar = google.calendar({ version: 'v3', auth });
} catch (err) {
assert(err instanceof Error);
throw new Error(`Authentication failed: ${err.message}`);
if (err instanceof Error) {
throw new Error(`Authentication failed: ${err.message}`);
} else {
throw new Error(`Authentication failed: ${err}`);

Check warning on line 24 in scripts/build-meetings.ts

View check run for this annotation

Codecov / codecov/patch

scripts/build-meetings.ts#L24

Added line #L24 was not covered by tests
}
}

let eventsItems;
Expand Down
8 changes: 5 additions & 3 deletions scripts/finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { mkdir } from 'fs/promises';
import { resolve } from 'path';

Expand Down Expand Up @@ -37,7 +36,10 @@ export async function buildFinanceInfoList({

await writeJSON(expensesLinkPath, expensesLinkJsonPath);
} catch (err) {
assert(err instanceof Error);
throw new Error(err.message);
if (err instanceof Error) {
throw new Error(`Error in buildFinanceInfoList: ${err.message}`);
} else {
throw new Error(`Error in buildFinanceInfoList: ${err}`);

Check warning on line 42 in scripts/finance/index.ts

View check run for this annotation

Codecov / codecov/patch

scripts/finance/index.ts#L42

Added line #L42 was not covered by tests
}
}
}
8 changes: 5 additions & 3 deletions scripts/tools/tools-object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import assert from 'assert';
import axios from 'axios';
import Fuse from 'fuse.js';

Expand Down Expand Up @@ -127,8 +126,11 @@ async function convertTools(data: ToolsData) {

return finalToolsObject;
} catch (err) {
assert(err instanceof Error);
throw new Error(`Error processing tool: ${err.message}`);
if (err instanceof Error) {
throw new Error(`Error processing tool: ${err.message}`);
} else {
throw new Error(`Error processing tool: ${err}`);

Check warning on line 132 in scripts/tools/tools-object.ts

View check run for this annotation

Codecov / codecov/patch

scripts/tools/tools-object.ts#L132

Added line #L132 was not covered by tests
}
}
}

Expand Down

0 comments on commit 9fe2983

Please sign in to comment.