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

Rename to unreachable error #24

Draft
wants to merge 2 commits into
base: filecoin
Choose a base branch
from
Draft
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
16 changes: 8 additions & 8 deletions src/common/commonResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Driver } from '../generated/graphql';
import GivenEventModel from '../given-event/GivenEventModel';
import DripListSplitReceiverModel from '../models/DripListSplitReceiverModel';
import type { Context } from '../server';
import shouldNeverHappen from '../utils/shouldNeverHappen';
import unreachableError from '../utils/unreachableError';
import type { AddressDriverId, DripListId, ProjectId } from './types';
import { DependencyType } from './types';
import getUserAddress from '../utils/getUserAddress';
Expand All @@ -33,20 +33,20 @@ async function resolveTotalSplit(
const { fundeeDripListId, funderDripListId, funderProjectId } = parent;
recipientAccountId = fundeeDripListId;
incomingAccountId =
funderDripListId || funderProjectId || shouldNeverHappen();
funderDripListId || funderProjectId || unreachableError();
} else if (parent instanceof RepoDriverSplitReceiverModel) {
const { fundeeProjectId, funderDripListId, funderProjectId } = parent;
recipientAccountId = fundeeProjectId;
incomingAccountId =
funderDripListId || funderProjectId || shouldNeverHappen();
funderDripListId || funderProjectId || unreachableError();
} else if (parent instanceof AddressDriverSplitReceiverModel) {
const { fundeeAccountId, funderDripListId, funderProjectId } = parent;

recipientAccountId = fundeeAccountId;
incomingAccountId =
funderDripListId || funderProjectId || shouldNeverHappen();
funderDripListId || funderProjectId || unreachableError();
} else {
shouldNeverHappen('Invalid SupportItem type');
unreachableError('Invalid SupportItem type');
}

const splitEvents = await SplitEventModel.findAll({
Expand Down Expand Up @@ -91,7 +91,7 @@ const commonResolvers = {
case AddressDriverSplitReceiverType.DripListDependency:
return 'DripListSupport';
default:
return shouldNeverHappen('Invalid SupportItem type');
return unreachableError('Invalid SupportItem type');
}
}

Expand All @@ -116,7 +116,7 @@ const commonResolvers = {

return {
driver: Driver.REPO,
accountId: project ? project.id : shouldNeverHappen(),
accountId: project ? project.id : unreachableError(),
};
},
date: (parent: { blockTimestamp: Date }): Date => parent.blockTimestamp,
Expand Down Expand Up @@ -150,7 +150,7 @@ const commonResolvers = {

return {
driver: Driver.NFT,
accountId: dripList ? dripList.id : shouldNeverHappen(),
accountId: dripList ? dripList.id : unreachableError(),
};
},
date: (parent: { blockTimestamp: Date }): Date => parent.blockTimestamp,
Expand Down
4 changes: 2 additions & 2 deletions src/common/getProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Provider } from 'ethers';
import { FetchRequest, JsonRpcProvider, WebSocketProvider } from 'ethers';
import shouldNeverHappen from '../utils/shouldNeverHappen';
import unreachableError from '../utils/unreachableError';
import appSettings from './appSettings';

let providerInstance: Provider | null = null;
Expand All @@ -16,7 +16,7 @@ export default function getProvider(): Provider {
} else if (rpcUrl.startsWith('wss')) {
providerInstance = new WebSocketProvider(rpcUrl);
} else {
shouldNeverHappen(`Invalid RPC URL: ${rpcUrl}`);
unreachableError(`Invalid RPC URL: ${rpcUrl}`);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/drip-list/dripListResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
SplitsReceiver,
} from '../generated/graphql';
import { Driver } from '../generated/graphql';
import shouldNeverHappen from '../utils/shouldNeverHappen';
import unreachableError from '../utils/unreachableError';
import type { Context } from '../server';
import type GitProjectModel from '../project/ProjectModel';
import assert, { isDripListId } from '../utils/assert';
Expand Down Expand Up @@ -65,8 +65,8 @@ const dripListResolvers = {
dripList.previousOwnerAddress,
owner: (dripList: DripListModel): AddressDriverAccount => ({
driver: Driver.ADDRESS,
accountId: dripList.ownerAccountId || shouldNeverHappen(),
address: (dripList.ownerAddress as string) || shouldNeverHappen(),
accountId: dripList.ownerAccountId || unreachableError(),
address: (dripList.ownerAddress as string) || unreachableError(),
}),
account: (dripList: DripListModel): NftDriverAccount => ({
driver: Driver.NFT,
Expand Down Expand Up @@ -126,7 +126,7 @@ const dripListResolvers = {
)
.find(
(p) => (p as any).id === receiver.fundeeProjectId,
) as unknown as Project) || shouldNeverHappen(),
) as unknown as Project) || unreachableError(),
}));

const receiversOfTypeDripListModels =
Expand All @@ -153,7 +153,7 @@ const dripListResolvers = {
)
.find(
(p) => (p as any).id === receiver.fundeeDripListId,
) as unknown as DripList) || shouldNeverHappen(),
) as unknown as DripList) || unreachableError(),
}),
);

Expand Down
34 changes: 16 additions & 18 deletions src/project/projectResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type ProjectModel from './ProjectModel';
import { ProjectVerificationStatus } from './ProjectModel';
import { splitProjectName } from './projectUtils';
import shouldNeverHappen from '../utils/shouldNeverHappen';
import unreachableError from '../utils/unreachableError';
import { Driver } from '../generated/graphql';
import type {
SplitsReceiver,
Expand Down Expand Up @@ -115,7 +115,7 @@ const projectResolvers = {
},
ClaimedProject: {
color: (project: ProjectModel): string =>
project.color || shouldNeverHappen(),
project.color || unreachableError(),
description: (project: ProjectModel): string | null => project.description,
emoji: (project: ProjectModel): string => project.emoji || '💧',
avatar: (project: ProjectModel): any => {
Expand All @@ -131,24 +131,23 @@ const projectResolvers = {
},
owner: (project: ProjectModel): AddressDriverAccount => ({
driver: Driver.ADDRESS,
accountId: project.ownerAccountId || shouldNeverHappen(),
address: (project.ownerAddress as string) || shouldNeverHappen(),
accountId: project.ownerAccountId || unreachableError(),
address: (project.ownerAddress as string) || unreachableError(),
}),
account: (project: ProjectModel): RepoDriverAccount => ({
driver: Driver.REPO,
accountId: project.id,
}),
source: (project: ProjectModel): Source => ({
url: project.url || shouldNeverHappen(),
repoName: splitProjectName(project.name || shouldNeverHappen()).repoName,
ownerName: splitProjectName(project.name || shouldNeverHappen())
.ownerName,
forge: (project.forge as Forge) || shouldNeverHappen(),
url: project.url || unreachableError(),
repoName: splitProjectName(project.name || unreachableError()).repoName,
ownerName: splitProjectName(project.name || unreachableError()).ownerName,
forge: (project.forge as Forge) || unreachableError(),
}),
verificationStatus: (project: ProjectModel): ProjectVerificationStatus =>
project.verificationStatus === ProjectVerificationStatus.Claimed
? project.verificationStatus
: shouldNeverHappen(),
: unreachableError(),
splits: async (
project: ProjectModel,
_: any,
Expand Down Expand Up @@ -218,7 +217,7 @@ const projectResolvers = {
)
.find(
(p) => (p as any).id === receiver.fundeeProjectId,
) as unknown as Project) || shouldNeverHappen(),
) as unknown as Project) || unreachableError(),
}),
);

Expand Down Expand Up @@ -246,7 +245,7 @@ const projectResolvers = {
)
.find(
(p) => (p as any).id === receiver.fundeeDripListId,
) as unknown as DripList) || shouldNeverHappen(),
) as unknown as DripList) || unreachableError(),
}),
);

Expand Down Expand Up @@ -321,7 +320,7 @@ const projectResolvers = {
return 'AddressReceiver';
}

return shouldNeverHappen();
return unreachableError();
},
},
UnclaimedProject: {
Expand All @@ -333,12 +332,11 @@ const projectResolvers = {
},
source(project: ProjectModel): Source {
return {
url: project.url || shouldNeverHappen(),
repoName: splitProjectName(project.name || shouldNeverHappen())
.repoName,
ownerName: splitProjectName(project.name || shouldNeverHappen())
url: project.url || unreachableError(),
repoName: splitProjectName(project.name || unreachableError()).repoName,
ownerName: splitProjectName(project.name || unreachableError())
.ownerName,
forge: (project.forge as Forge) || shouldNeverHappen(),
forge: (project.forge as Forge) || unreachableError(),
};
},
verificationStatus(project: ProjectModel): ProjectVerificationStatus {
Expand Down
6 changes: 3 additions & 3 deletions src/project/projectUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import type { FakeUnclaimedProject, Forge, ProjectId } from '../common/types';
import shouldNeverHappen from '../utils/shouldNeverHappen';
import unreachableError from '../utils/unreachableError';
import type ProjectModel from './ProjectModel';
import { ProjectVerificationStatus } from './ProjectModel';
import { RepoDriver__factory } from '../generated/contracts';
Expand Down Expand Up @@ -50,7 +50,7 @@ function toContractForge(forge: Forge): 0 | 1 {
case `GitLab`:
return 1;
default:
return shouldNeverHappen(`Forge ${forge} not supported.`);
return unreachableError(`Forge ${forge} not supported.`);
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ function toForge(forge: string): Forge {
case 'gitlab':
return `GitLab`;
default:
return shouldNeverHappen(`Forge ${forge} not supported.`);
return unreachableError(`Forge ${forge} not supported.`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/stream/streamResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Driver, type StreamWhereInput } from '../generated/graphql';
import type { Context } from '../server';
import shouldNeverHappen from '../utils/shouldNeverHappen';
import unreachableError from '../utils/unreachableError';

const streamResolvers = {
Query: {
Expand All @@ -24,7 +24,7 @@ const streamResolvers = {
);
}

throw shouldNeverHappen();
throw unreachableError();
},
sender: (parent: any, _: any, { dataSources }: Context) => {
if (parent.sender.driver === Driver.ADDRESS) {
Expand All @@ -35,7 +35,7 @@ const streamResolvers = {
return dataSources.dripListsDb.getDripListById(parent.sender.accountId);
}

throw shouldNeverHappen();
throw unreachableError();
},
},
};
Expand Down
3 changes: 0 additions & 3 deletions src/utils/shouldNeverHappen.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/utils/unreachableError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function unreachableError(message?: string): never {
throw new Error(`Unreachable code${message ? `: ${message}` : '.'}`);
}
Loading