itty-durable icon indicating copy to clipboard operation
itty-durable copied to clipboard

Itty-Durable sending empty string response causing an "Unhandled Promise Rejection"

Open 4x4notfound opened this issue 3 years ago • 1 comments

I'm using itty durable and manually creating a proxyDurable the following way:

export const initAccountNodeByName = async (
  name: string,
  durableObject: DurableObjectNamespace
) => {
  const proxy = await proxyDurable(durableObject, {
    name: 'account',
    class: Account,
    parse: true,
  })

  const node = proxy.get(name) as Account
  return node
}

Everything works great but in the logs there the following errors occurs.

YN0000: { text: '' }
➤ YN0000:  Trace: 
➤ YN0000::     at Request.json (/Users/adrianmaurer/Code/kubelt/node_modules/undici/lib/fetch/body.js:392:17)
➤ YN0000: :     at runNextTicks (node:internal/process/task_queues:60:5)
➤ YN0000: :     at processImmediate (node:internal/timers:442:9)
➤ YN0000: :     at process.topLevelDomainCallback (node:domain:161:15)
➤ YN0000::     at process.callbackTrampoline (node:internal/async_hooks:128:24)
➤ YN0000: :     at Request.json (/node_modules/@miniflare/core/src/standards/http.ts:333:18)
➤ YN0000:      at withContent (/node_modules/itty-router-extras/middleware/withContent.js:1:132)
➤ YN0000: :     at Object.handle (//node_modules/itty-router/dist/itty-router.min.js:1:590)

note: this does not break the app but it's strange that the proxy object is returning an empty string response.

Here is the DO:

export default class Account extends createDurable({
  autoReturn: true,
  autoPersist: false,
}) {
  declare state: Node.IttyDurableObjectState<Environment>

  async getProfile(): Promise<Profile | null> {
    const stored = await this.state.storage.get<Profile>('profile')
    return stored || null
  }

  async setProfile(profile: Profile): Promise<void> {
    return this.state.storage.put('profile', profile)
  }
}

4x4notfound avatar Jan 04 '23 00:01 4x4notfound

One more note: Logging the responses for the DO never yields an empty string

4x4notfound avatar Jan 04 '23 00:01 4x4notfound