Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Cannot set value without explicit ttl #919

Closed
allenheltondev opened this issue Sep 18, 2023 · 2 comments
Closed

[Bug] Cannot set value without explicit ttl #919

allenheltondev opened this issue Sep 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@allenheltondev
Copy link

If I run this code, I get the error listed at the bottom.

const client =  await CacheClient.create({
   credentialProvider: CredentialProvider.fromEnvironmentVariable({environmentVariableName: 'MOMENTO_AUTH'}),
   configuration: Configurations.Laptop.latest(),
   defaultTtl: 300
 });

  const cacheClient  = client.cache('chatgpt');
  const r = await cacheClient.set('image', 'data');

Error:
/home/runner/MomentoCollections/node_modules/@gomomento/sdk/dist/src/internal/cache-data-client.js:173
this.logger.trace(Issuing 'set' request; key: ${key.toString()}, value length: ${value.length}, ttl: ${ttlToUse.toString()});

TypeError: Cannot read properties of undefined (reading 'toString')
at CacheDataClient.set (/home/runner/MomentoCollections/node_modules/@gomomento/sdk/dist/src/internal/cache-data-client.js:173:122)
at CacheClient.set (/home/runner/MomentoCollections/node_modules/@gomomento/sdk-core/dist/src/internal/clients/cache/AbstractCacheClient.js:88:29)
at MomentoCache.set (/home/runner/MomentoCollections/node_modules/@gomomento/sdk-core/dist/src/internal/clients/cache/momento-cache.js:13:33)
at run (/home/runner/MomentoCollections/index.js:13:31)
at Object. (/home/runner/MomentoCollections/index.js:20:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)

Thoughts
I think ttlToUse is not being populated if not explicitly provided.

SDK Version
v1.39.3

@allenheltondev allenheltondev added the bug Something isn't working label Sep 18, 2023
@cprice404
Copy link
Contributor

There is a test that I believe covers this:

const cache = cacheClient.cache(integrationTestCacheName);
const setResponse = await cache.set(cacheKey, cacheValue);
expectWithMessage(() => {
expect(setResponse).toBeInstanceOf(CacheSet.Success);
}, `expected SUCCESS but got ${setResponse.toString()}`);
const getResponse = await cache.get(cacheKey);
expectWithMessage(() => {
expect(getResponse).toBeInstanceOf(CacheGet.Hit);
}, `expected HIT but got ${getResponse.toString()}`);
if (getResponse instanceof CacheGet.Hit) {
expect(getResponse.valueString()).toEqual(cacheValue);
}

So I'm not quite sure what's going on here, but we can try to repro, this would definitely be an urgent bug to fix :)

@cprice404
Copy link
Contributor

This turned out to be an issue with a constructor argument name (defaultTtl instead of defaultTtlSeconds). Updated #649 to add explicit runtime checks for constructor arguments for JS users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants