Skip to content

Conversation

jskeet
Copy link
Member

@jskeet jskeet commented Apr 29, 2020

Would fix #37 if we decided to do this. We want to review this as a possible cross-platform approach though.

Would fix GoogleCloudPlatform#37 if we decided to do this. We want to review this as a possible cross-platform approach though.
@jskeet jskeet changed the title DRAFT: One possibly approach for simpler errors. DRAFT: One possible approach for simpler errors. Apr 29, 2020
@jskeet
Copy link
Member Author

jskeet commented Apr 29, 2020

Note: we could potentially add an adapter to the Google.Cloud.Functions.Framework type that basically had the code that's in FunctionEnvironment.Execute. That would make it easier to get a consistent experience when not using the Invoker package.
Let's worry about those implementation details once we've decided on the user experience in general.

Copy link
Member

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few comments

namespace Google.Cloud.Functions.Framework
{
// More decisions and considerations:
// - Another message to be set on the response? (As content? Something else?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. It might be used to write random content, specially if success status codes are allowed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well users can already write whatever content they want... it just gives an easy way to give callers a hint as to what's wrong (e.g. which required parameter is missing)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's true, I guess what I really don't like is the combination of this and being able to set success status code from the exception. I can imagine it being used to control flow and that makes me icky.
I like a lot what MVC has with the IActionResult and all sorts of derived types, even types for bad status code like UnauthorizedResult, NotFoundResult, etc. It gave the opportunity to cleanly control for those cases I think.

{
// More decisions and considerations:
// - Another message to be set on the response? (As content? Something else?)
// - Prohibit success status codes?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say yes, although maybe provide another way to set different success status codes? But definitely wouldn't like an exception controlling different success statuses.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would certainly be an anti-pattern to do so. Whether that makes it worth explicitly prohibiting or not, I don't know... but I'm happy enough to do it.

var function = context.RequestServices.GetRequiredService<IHttpFunction>();
await function.HandleAsync(context);
}
catch (FunctionException ex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe catch everything else as well to log a rethrow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that - any exceptions that make it to the very top of the pipeline are logged and the response becomes a 500.

@grant
Copy link
Contributor

grant commented May 27, 2020

Not sure if I am the best person to review these changes. Going to unassign, but feel free to ping me on docs or other non .NET specific changes.

@jskeet
Copy link
Member Author

jskeet commented Sep 24, 2020

Closing as I'm not expecting us to do this for beta, and it's now rather ancient. (Recreating is probably simpler than rebasing.)

@jskeet jskeet closed this Sep 24, 2020
@jskeet jskeet deleted the function-exception branch September 24, 2020 16:37
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 this pull request may close these issues.

Work out what to do about communicating errors from functions to callers
3 participants