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

Transport Agnostic Errors / EventStream errors - consolidate error handling #216

Merged
merged 10 commits into from
Aug 26, 2024

Conversation

alextwoods
Copy link
Contributor

@alextwoods alextwoods commented Aug 20, 2024

Description of changes:
Previously the generated Errors module was specific to the HTTP Transport. This PR makes the generated errors transport agnostic, allowing errors classes to be used as either operation response errors (with or without http transports) and event errors. This required moving the creation of events into the parsers, which do have the transport specific knowledge and the the knowledge of which error class they map to.

Consolidates the error handling for event stream errors to a single handler for consistency with the SDK specification. Adds modeled event stream errors to new generated Errors::EventStream module. Note - these must be in a separate namespace as the error structures may also be the target of operation errors.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@alextwoods alextwoods changed the title EventStream errors - consolidate error handling Transport Agnostic Errors / EventStream errors - consolidate error handling Aug 21, 2024
Copy link
Contributor

@mullermp mullermp left a comment

Choose a reason for hiding this comment

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

Nice!

data.top_level = map['TopLevel']
data.nested = (ComplexNestedErrorData.parse(map['Nested']) unless map['Nested'].nil?)
data
unless body.empty?
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if body is empty, wouldn't we parse an empty map easily here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in at least some cases we used to fail on this (xml?) - it also means you can skip any parsing + checking for each field in the map when you already know you don't need to do any more parsing. We used to just return the data here immediately, so I think this new logic is equivalent to that + the error class wrapper.

@@ -1,25 +0,0 @@
# frozen_string_literal: true
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's rbs for this file? Check to see if any other rbs needs updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call removed and checked all other rbs.

@@ -23,12 +23,20 @@ class ApiClientError < ApiError; end
class ApiServerError < ApiError; end

class ModeledError < ApiClientError; end

module Parsers
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be under TestParsers, next to TestErrors? (Errors and Parsers are siblings right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was trying to avoid extra namespaces. The module arrangement doesn't really matter here, though I guess technically it doesn't reflect what we generate. To be fully accurate we would need:

module TestService
  module Errors
     class ModeledError < ApiClientError; end # and all the other ones
   end

  module Parsers
      class ModeledError; end
  end
end

But it didn't really seem worth it to create more modules/nest more deeply here.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general I didn't like that we pollute the test namespace. There must be a fix.. maybe we should make a unit test service somehow? I guess like an API helper.

@alextwoods alextwoods merged commit 119faee into main Aug 26, 2024
25 of 26 checks passed
@alextwoods alextwoods deleted the es_errors branch August 26, 2024 16:50
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.

2 participants