Skip to content

Commit

Permalink
Moved ensure created inside try catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Feb 10, 2025
1 parent 20eb16c commit 4e79aeb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/packages/emmett-sqlite/src/eventStore/SQLiteEventStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export const getSQLiteEventStore = (
db = createConnection();
}

await ensureSchemaExists();
let stream;
try {
await ensureSchemaExists();
stream = await readStream<EventType>(db, streamName, options);
} catch (err: Error) {
closeConnection();
Expand All @@ -185,15 +185,17 @@ export const getSQLiteEventStore = (
db = createConnection();
}

await ensureSchemaExists();
// TODO: This has to be smarter when we introduce urn-based resolution
const [firstPart, ...rest] = streamName.split('-');

const streamType =
firstPart && rest.length > 0 ? firstPart : 'emt:unknown';

let appendResult;

try {
await ensureSchemaExists();

appendResult = await appendToStream(
db,
streamName,
Expand Down

0 comments on commit 4e79aeb

Please sign in to comment.