Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
fix: include actual key in error message of KVS' `setValue` (#2411)
Jiří Moravčík9089bf139b71
diff --git a/packages/core/src/storages/key_value_store.ts b/packages/core/src/storages/key_value_store.tsindex 5c3077cff..6167e9192 100644--- a/packages/core/src/storages/key_value_store.ts+++ b/packages/core/src/storages/key_value_store.ts@@ -323,7 +323,7 @@ export class KeyValueStore {ow(key, 'key', ow.string.nonEmpty);ow(key, ow.string.validate((k) => ({validator: ow.isValid(k, ow.string.matches(KEY_VALUE_STORE_KEY_REGEX)),- message: 'The "key" argument must be at most 256 characters long and only contain the following characters: a-zA-Z0-9!-_.\'()',+ message: `The "key" argument "${key}" must be at most 256 characters long and only contain the following characters: a-zA-Z0-9!-_.'()`,})));if (options.contentType&& !(ow.isValid(value, ow.any(ow.string, ow.buffer)) || (ow.isValid(value, ow.object) && typeof (value as Dictionary).pipe === 'function'))) {diff --git a/test/core/storages/key_value_store.test.ts b/test/core/storages/key_value_store.test.tsindex dd01ab1d2..95a2eaf84 100644--- a/test/core/storages/key_value_store.test.ts+++ b/test/core/storages/key_value_store.test.ts@@ -225,26 +225,16 @@ describe('KeyValueStore', () => {});const INVALID_CHARACTERS = '?|\\/"*<>%:';- let counter = 0;-for (const char of INVALID_CHARACTERS) {- try {- await store.setValue(`my_id_${char}`, 'value');- } catch (err) {- if ((err as Error).message.match('The "key" argument must be at most 256 characters')) counter++;- }+ const key = `my_id_${char}`;+ const err = `The "key" argument "${key}" must be at most 256 characters`;+ await expect(store.setValue(key, 'value')).rejects.toThrow(err);}- expect(counter).toEqual(INVALID_CHARACTERS.length);-- // TODO: This throws "ENAMETOOLONG: name too long, unlink" !!!- // await store.setValue('X'.repeat(256), 'value');// test max length- try {- await store.setValue('X'.repeat(257), 'value');- } catch (err) {- if ((err as Error).message.match('The "key" parameter must be at most 256 characters')) counter++;- }+ const longKey = 'X'.repeat(257);+ const err = `The "key" argument "${longKey}" must be at most 256 characters`;+ await expect(store.setValue(longKey)).rejects.toThrow(err);});test('correctly adds charset to content type', async () => {