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

Fix isAction type guard #186

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/renderer/lib/config-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { isAction } from './helpers';
export const configMiddleware: Middleware<{}, AppReduxState> =
(_store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
throw new Error(
'Invalid action dispatched in config: ' + JSON.stringify(action)
);
}
switch (action.type) {
case 'SET_INITIAL_TOKEN':
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/lib/electron-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ function scrollToTopNotification() {
export const electronMiddleware: Middleware<{}, AppReduxState> =
(_store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
throw new Error(
'Invalid action dispatched in electron: ' + JSON.stringify(action)
);
}
switch (action.type) {
case 'OPEN_URL':
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/lib/github-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export function createGitHubMiddleware(): Middleware<{}, AppReduxState> {

return (store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
throw new Error(
'Invalid action dispatched in github controls: ' +
JSON.stringify(action)
);
}
switch (action.type) {
case 'MARK_NOTE_READ': {
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/lib/gitnews-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ let currentDemoNotifications = createDemoNotifications();
export function createFetcher(): Middleware<{}, AppReduxState> {
const fetcher: Middleware<object, AppReduxState> =
(store) => (next) => (action) => {
if (!isAction(action) || !isDispatch(next)) {
throw new Error('Invalid action dispatched');
if (!isAction(action)) {
throw new Error(
'Invalid action dispatched in fetcher: ' + JSON.stringify(action)
);
}
if (!isDispatch(next)) {
throw new Error('Invalid dispatcher in fetcher');
}
if (action.type === 'MARK_NOTE_READ' && store.getState().isDemoMode) {
currentDemoNotifications = currentDemoNotifications.map((note) => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function getSecondsUntilNextFetch(

export function isAction(action: unknown): action is AppReduxAction {
const typedAction = action as AppReduxAction;
if (!('type' in typedAction) || !('token' in typedAction)) {
if (!('type' in typedAction)) {
return false;
}
return true;
Expand Down
Loading