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

Misleading ServiceActor::ArgumentError message under specific circumstances #131

Closed
viralpraxis opened this issue Feb 28, 2024 · 8 comments · Fixed by #135
Closed

Misleading ServiceActor::ArgumentError message under specific circumstances #131

viralpraxis opened this issue Feb 28, 2024 · 8 comments · Fixed by #135

Comments

@viralpraxis
Copy link
Contributor

viralpraxis commented Feb 28, 2024

Given the following actor

class TestActor < Actor
  input :value, type: Integer
  output :value_result, type: Integer, allow_nil: true
end

Evaluating TestActor.call(value: 1) leads to

ServiceActor::ArgumentError:
  The "value_result" input on "TestActor" is missing

(note the "input" while value_result is defined as output)

It does not happen if you define output without allow_nil: true

@sunny
Copy link
Owner

sunny commented Feb 28, 2024

Oh indeed. Right now the options only make sense to inputs as they are checked on call.

I’d be tempted to raise an error on any option passed to output as they are not supported.

Or we could make sure they actually work, but that would mean doing the check on the value_result= method call instead, I guess?

@viralpraxis
Copy link
Contributor Author

Or we could make sure they actually work, but that would mean doing the check on the value_result= method call instead, I guess?

I'd prefer to make it working, it seems to be quite useful

@sunny
Copy link
Owner

sunny commented Feb 29, 2024

Happy to accept a PR to make type: work for outputs 🙏🏻

Actually instead of on the #value_result= method call it would make more sense to do that at the end of the #call, when exiting the actor.

@viralpraxis
Copy link
Contributor Author

Hm, It seems like I misunderstood you.

The following actor

# frozen_string_literal: true

class AddGreetingWithDefault < Actor
  input :name, default: "world", type: String
  output :greeting, type: String

  def call
    self.greeting = 1
  end
end

works quite good, it throws

 ServiceActor::ArgumentError:
   The "greeting" output on "AddGreetingWithDefault" must be of type "String" but was "Integer"

@viralpraxis
Copy link
Contributor Author

It seels like the probelm is hardcoded input

"The \"#{@input_key}\" input on \"#{@actor}\" is missing",

which should be replaced with @origin

@sunny
Copy link
Owner

sunny commented Feb 29, 2024

Yes! My bad, I’ve misunderstood the issue. I forgot that checks actually worked on outputs, I just never used them 🙈

I think the DefaultCheck doesn’t make much sense on outputs and should be probably be skipped in that case.

@viralpraxis
Copy link
Contributor Author

Just to make sure I got you correctly, current behavior of

class WithUnsetOutput < Actor
  output :value, type: String, allow_nil: true
end

is

ServiceActor::ArgumentError:
The "value" input on "WithUnsetOutput" is missing

And if we skep default_check on outputs we'd expect it to complete successfuly with value == nil, right?

@sunny
Copy link
Owner

sunny commented Feb 29, 2024

Yeah, I think that would make sense.

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

Successfully merging a pull request may close this issue.

2 participants