Skip to content

Commit

Permalink
use assert instead of new error
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej-langr committed Dec 28, 2024
1 parent 608cb85 commit c2a7c1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 2 additions & 6 deletions packages/auth-provider-automerge-repo/src/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
* Creates a team and registers it with all of our sync servers.
*/
public async createTeam(teamName: string) {
if (!this.#user) {
throw new Error('Cannot create team as user is missing on AuthProvider')
}
assert(this.#user, 'Cannot create team as user is missing on AuthProvider')

const team = Auth.createTeam(teamName, {
device: this.#device,
Expand Down Expand Up @@ -665,9 +663,7 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {

const savedShares = unpack(serializedState) as SerializedState

if (!this.#user) {
throw new Error('Cannot load state as user is missing on AuthProvider')
}
assert(this.#user, 'Cannot load state as user is missing on AuthProvider')

await Promise.all(
Object.values(savedShares).map(async share => {
Expand Down
4 changes: 1 addition & 3 deletions packages/auth/src/connection/getDeviceUserFromGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export const getDeviceUserFromGraph = ({
const userKeyring = select.keyring(state, { type: USER, name: userId }, starterKeys)
const keys = getLatestGeneration(userKeyring)

if (!keys) {
throw new Error('Failed to get device user from graph as there are no keys for user keyring')
}
assert(keys, 'Failed to get device user from graph as there are no keys for user keyring')

const user: UserWithSecrets = { userName, userId, keys }

Expand Down

0 comments on commit c2a7c1b

Please sign in to comment.