Skip to content

Commit

Permalink
Throw when creating tx (simplify)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Jan 15, 2025
1 parent 06f9f97 commit 13e46f2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class HypercoreStorage {
}

atomize (atom) {
if (this.snapshotted) throw new Error('Cannot atomize a snapshot')
if (this.atom && this.atom !== atom) throw new Error('Cannot atomize and atomized session with a new atom')
return new HypercoreStorage(this.store, this.db.session(), this.core, atom.view, atom)
}
Expand Down Expand Up @@ -164,7 +163,6 @@ class HypercoreStorage {
}

async createSession (name, head) {
if (this.snapshotted) throw new Error('Cannot create session on snapshot')
const rx = this.read()

const existingSessionsPromise = rx.getSessions()
Expand Down Expand Up @@ -250,7 +248,6 @@ class HypercoreStorage {
}

write () {
if (this.snapshotted) throw new Error('Cannot write to snapshot')
return new CoreTX(this.core, this.db, this.atom ? this.view : null, [])
}

Expand Down
1 change: 1 addition & 0 deletions lib/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CORE_HINTS = schema.getEncoding('@core/hints')

class CoreTX {
constructor (core, db, view, changes) {
if (db.snapshotted) throw new Error('Cannot open core tx on snapshot')
this.core = core
this.db = db
this.view = view
Expand Down
14 changes: 2 additions & 12 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ test('cannot open tx on snapshot', async (t) => {
const snap = core.snapshot()
t.exception(
() => snap.write(),
/Cannot write to snapshot/
/Cannot open core tx on snapshot/
)
})

Expand All @@ -647,16 +647,6 @@ test('cannot create sessions on snapshot', async (t) => {

await t.exception(
async () => await snap.createSession(),
/Cannot create session on snapshot/
)
})

test('cannot atomize snapshot', async (t) => {
const core = await createCore(t)
const snap = core.snapshot()

await t.exception(
async () => snap.atomize(snap.createAtom()),
/Cannot atomize a snapshot/
/Cannot open core tx on snapshot/
)
})

0 comments on commit 13e46f2

Please sign in to comment.