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

TypeError: Cannot use 'in' operator to search for '_op' in undefined #2708

Open
dilame opened this issue May 7, 2024 · 7 comments
Open

TypeError: Cannot use 'in' operator to search for '_op' in undefined #2708

dilame opened this issue May 7, 2024 · 7 comments

Comments

@dilame
Copy link
Contributor

dilame commented May 7, 2024

What version of Effect is running?

3.1.2

What steps can reproduce the bug?

import {Effect, TestClock, Console, Schedule} from "effect"

const test = Effect.gen(function* () {
    const sleeps = yield* TestClock.sleeps();
    console.log(sleeps);

}).pipe(Effect.repeat(Schedule.addDelay(Schedule.forever, () => '1 second')))

Effect.runPromise(test)

What is the expected behavior?

No response

What do you see instead?

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

TypeError: Cannot use 'in' operator to search for '_op' in undefined
    at runLoop (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/fiberRuntime.ts:1292:20)
    at evaluateEffect (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/fiberRuntime.ts:891:27)
    at start (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/fiberRuntime.ts:945:14)
    at <anonymous> (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:92:18)
    at resolve (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:283:38)
    at new Promise (<anonymous>)
    at <anonymous> (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:278:3)
    at Module.<anonymous> (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:259:32)
    at <anonymous> (/Users/bowzee/WebstormProjects/sandbox/src/effect.ts:24:8)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25) {
  name: '(FiberFailure) TypeError',
  [Symbol(effect/Runtime/FiberFailure)]: Symbol(effect/Runtime/FiberFailure),
  [Symbol(effect/Runtime/FiberFailure/Cause)]: {
    _tag: 'Die',
    defect: TypeError: Cannot use 'in' operator to search for '_op' in undefined
        at runLoop (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/fiberRuntime.ts:1292:20)
        at evaluateEffect (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/fiberRuntime.ts:891:27)
        at start (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/fiberRuntime.ts:945:14)
        at <anonymous> (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:92:18)
        at resolve (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:283:38)
        at new Promise (<anonymous>)
        at <anonymous> (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:278:3)
        at Module.<anonymous> (/Users/bowzee/WebstormProjects/sandbox/node_modules/effect/src/internal/runtime.ts:259:32)
        at <anonymous> (/Users/bowzee/WebstormProjects/sandbox/src/effect.ts:24:8)
        at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
  }
}

Node.js v21.4.0

Additional information

I understand, that my code makes not too much sense, but i guess it should not lead to TypeError

@dilame dilame added the bug Something isn't working label May 7, 2024
@mikearnaldi
Copy link
Member

To use TestClock you need to provide a TestContext like:

import {Effect, TestClock, TestContext, Schedule} from "effect"

const test = Effect.gen(function* () {
    const sleeps = yield* TestClock.sleeps();
    console.log(sleeps);

}).pipe(Effect.repeat(Schedule.addDelay(Schedule.forever, () => '1 second')))

Effect.runPromise(test.pipe(Effect.provide(TestContext.TestContext)))

The reason this is not tracked at the type level is because otherwise test implementations wouldn't be composable with app code so we opted for a fiber ref

@mikearnaldi mikearnaldi added working as intended and removed bug Something isn't working labels May 10, 2024
@dilame
Copy link
Contributor Author

dilame commented May 11, 2024

Yes, i understand that i need to provide TestContext in order to use TestClock, i also understand that it is not tracked at type level, but the error in runtime doesn't provide a clear understanding of whats going wrong, is it intended?

@mikearnaldi
Copy link
Member

We can try to improve the error message but not sure we have enough info at runtime to make it nice

@DScheglov
Copy link

We can try to improve the error message but not sure we have enough info at runtime to make it nice

Is there any way to make this code fail at compile time?
Without it, dependency injection works as a dynamic service locator and will cause heavy debugging.

@mikearnaldi
Copy link
Member

We can try to improve the error message but not sure we have enough info at runtime to make it nice

Is there any way to make this code fail at compile time? Without it, dependency injection works as a dynamic service locator and will cause heavy debugging.

As explained it is like this intentionally. For typed dependencies you have Context, in this case we use a FiberRef to not have explicit types. If using the TestClock added a dependency to the type you would not be able to use it in place of production code.

@dilame
Copy link
Contributor Author

dilame commented May 20, 2024

not sure we have enough info at runtime to make it nice

Something like "Some of the required dependencies not found" message would be better that TypeError at runtime anyway IMHO:)

And, BTW, maybe we could depend on Clock on type-level, and substitute it with TestClock when needed?

@mikearnaldi
Copy link
Member

mikearnaldi commented May 20, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants