Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
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
25 changes: 16 additions & 9 deletions libraries/botbuilder-azure-blobs/src/blobsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,25 @@ export class BlobsStorage implements Storage {

await pmap(
Object.entries(changes),
([key, { eTag = '', ...change }]) => {
const blob = this._containerClient.getBlockBlobClient(sanitizeBlobKey(key));
const serialized = JSON.stringify(change);

return blob.upload(serialized, serialized.length, {
conditions: typeof eTag === 'string' && eTag !== '*' ? { ifMatch: eTag } : {},
blobHTTPHeaders: { blobContentType: 'application/json' },
});
async ([key, { eTag = '', ...change }]) => {
try {
const blob = this._containerClient.getBlockBlobClient(sanitizeBlobKey(key));
const serialized = JSON.stringify(change);
return await blob.upload(serialized, serialized.length, {
conditions: typeof eTag === 'string' && eTag !== '*' ? { ifMatch: eTag } : {},
blobHTTPHeaders: { blobContentType: 'application/json' },
});
} catch (err: any) {
if (err.statusCode === 412) {
throw new Error(`Storage: error writing "${key}" due to eTag conflict.`);
} else {
throw err;
}
}
},
{
concurrency: this._concurrency,
}
},
);
}

Expand Down
15 changes: 15 additions & 0 deletions libraries/botbuilder-azure-blobs/tests/blobsStorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ describe('BlobsStorage', function () {
maybeIt('should write a set of values', async () => {
await client.write({ foo, bar });
});

maybeIt('should fail with eTag conflict error', async () => {
const changes = {
item1: {
key1: 'value1',
eTag: 'etag1',
},
item2: {
key2: 'value2',
eTag: 'etag1',
},
};

await assert.rejects(() => client.write(changes), 'Storage: error writing "item2" due to eTag conflict.');
});
});

describe('delete()', function () {
Expand Down