Git Product home page Git Product logo

dry-effects's People

Contributors

actions-user avatar alassek avatar alshitov avatar citizen428 avatar deepj avatar dry-bot avatar ermolaev avatar flash-gordon avatar jtzero avatar leehambley avatar olleolleolle avatar rwalters avatar smnkrt avatar solnic avatar swilgosz avatar timriley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dry-effects's Issues

wrapping the effect handler with a catch block

Issue when wrapping the effect handler with a catch block

Some libraries / frameworks like warden and hanami, use throw and catch to manage the flow of execution.
I am trying to use dry-effects to wrap all the call methods for hanami controller actions, although when a :halt is thrown instead of it being caught by the framework, it is being caught by dry-effects with the following error:

uncaught throw :error (UncaughtThrowError)

which is coming from:

lib/dry/effects/frame.rb:39:in block in spawn_fiber'`

To Reproduce

class Foo
  include ::Dry::Effects::Handler.Reader(:test)

  def call
    catch(:error) do
      with_test(:foobar) do
        throw :error
      end
    end
    puts 'we should have got here'
  end
end

Foo.new.call

Expected behavior

I would expect dry-effects to ignore the specific throw and bubble it up

Incompatibility with ActiveSupport::TaggedLogging

Describe the bug

When using dry-effects (specifically something like include Dry::Effects::Handler::State(:counter), inside a provide(..) { ... } block, any ActiveSupport::TaggedLogging tags may be lost.

A bug report to Rails was opened by my colleague:

This issue has been opened here to draw the issue to your attention only. I don't know if it's appropriate to workaround AS here, or if some concession can be made to make this more reliable.

At least, maybe a documentation entry could be added to highlight the incompatibility.

To Reproduce

A simple example that simulates what's going on inside AS::TaggedLogging looks like this:

Thread.current[:fiber_local_var] = 'Result'
Fiber.new do
  puts Thread.current[:fiber_local_var]
end.resume
# => <Empty output>

Thread.current.thread_variable_set(:thread_local_var, 'Result')
Fiber.new do
  puts Thread.current.thread_variable_get(:thread_local_var)
end.resume
# => "Result"

In practice however trying to do something like this would/should cause the issue:

logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
include Dry::Effects::Handler.Resolve
include Dry::Effects.Resolve(:anything)
logger.tagged("A") do
  logger.info "before provide"
  provide(anything: :foo) { anything; logger.info "in provide" }
  logger.info "after provide"
end

Expected behavior

The code above should print:

[A] before provide
[A] in provide
[A] after provide

but it actually prints:

[A] before provide
in provide
[A] after provide

Your environment

$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
$ bin/rails version
Rails 6.0.2.1
$ uname -r
5.3.16-300.fc31.x86_64

Thread variables are not accessible

Describe the bug

Using state effect resets all Thread.current variables.

To Reproduce

include Dry::Effects::Handler.State(:updated_attributes)
include Dry::Effects.State(:updated_attributes)

def test
      puts "outside: #{Thread.current.keys}"
      clients_changes, result = with_updated_attributes(Hash.new { |hash, key| hash[key] = [] }) do
        puts "inside: #{Thread.current.keys}"
      end
end
Thread.current[:foo] = 'bar'
test 

Oututs:

outside: [:foo, :dry_effects_stack]
inside: [:dry_effects_stack]

Expected behavior

As you can see variables set outside of the with_updated_attributes block are not visible inside the block.
I expect the following output:

outside: [:foo, :dry_effects_stack]
inside: [:foo, :dry_effects_stack]

My environment

  • Affects my production application: NO
  • Ruby version: "2.6.5"
  • OS: MacOS
  • Dry Effects version: 0.1.5

Messy data in profilers (New Relic, etc.)

Describe the bug

Code wrapped by effect handler is not analyzed by profilers (such as New Relic and Skylight) properly (e.g. no sql queries data when wrapped in rails controller and complete mess when wrapped with middleware)

To Reproduce

Wrap code by effect handler and introduce some profiler in the app.

Expected behavior

Code is profiled as usual.

Your environment

  • Affects my production application: YES
  • Ruby version: 2.7.1
  • OS: .Ubuntu 20.04

I'm not sure whether it's new relic/skylight problem or dry's, but hope to get some hint at least.

[Security] Workflow sync_configs.yml is using vulnerable action actions/checkout

The workflow sync_configs.yml is referencing action actions/checkout using references v1. However this reference is missing the commit a6747255bd19d7a757dbdda8c654a9f84db19839 which may contain fix to the some vulnerability.
The vulnerability fix that is missing by actions version could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider to update the reference to the action.

Interrupt example from documentation not working

Describe the bug

Executing the code from the Basic Usage of the Interrupt guide does not yield the expected result.

To Reproduce

Execute the code from the example:

require 'dry/effects'

class RunDivision
  include Dry::Effects::Handler.Interrupt(:division_by_zero, as: :catch_zero_division)

  def call
    success, answer = catch_zero_division do
      yield
    end

    if success
      answer
    else
      :error
    end
  end
end

class Divide
  include Dry::Effects.Interrupt(:division_by_zero)

  def call(dividend, divisor)
    if divisor.zero?
      division_by_zero
    else
      dividend / divisor
    end
  end
end

run = RunDivision.new
divide = Divide.new

app = -> a, b { run.() { divide.(a, b) } }

Expected behavior

Expected:

app.(10, 2) # => 5
app.(1, 0) # => :error

Got:

app.(10, 2) # => :error
app.(1, 0) # => nil

Your environment

  • Affects my production application: NO
  • Ruby version: 2.6.5
  • Gem Version: 0.1.1
  • OS: macOS 10.15.1

I'd look into it myself, but won't have time today.

spec/intergration typo

Hey, I was browsing through the code to understand the goal of this lib and I thought I would let you know :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.