GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(parser): Improve error message when parsing models and envel… · dastra/powertools-lambda-python@aacb37d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • aws_lambda_powertools/utilities/parser
    • parser.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎aws_lambda_powertools/utilities/parser/parser.py‎

Copy file name to clipboardExpand all lines: aws_lambda_powertools/utilities/parser/parser.py
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,12 @@ def handler(event: Order, context: LambdaContext):
171171
try:
172172
logger.debug(f"Parsing and validating event model with envelope={envelope}")
173173
return envelope().parse(data=event, model=model)
174-
except AttributeError:
175-
raise InvalidEnvelopeError(f"Envelope must implement BaseEnvelope, envelope={envelope}")
174+
except AttributeError as exc:
175+
raise InvalidEnvelopeError(
176+
f"Error: {str(exc)}. Please ensure that both the Input model and the Envelope inherits from BaseModel,\n" # noqa E501
177+
"and your payload adheres to the specified Input model structure.\n"
178+
f"Envelope={envelope}\nModel={model}",
179+
)
176180

177181
try:
178182
disable_pydantic_v2_warning()
@@ -181,5 +185,9 @@ def handler(event: Order, context: LambdaContext):
181185
return model.parse_raw(event)
182186

183187
return model.parse_obj(event)
184-
except AttributeError:
185-
raise InvalidModelTypeError(f"Input model must implement BaseModel, model={model}")
188+
except AttributeError as exc:
189+
raise InvalidModelTypeError(
190+
f"Error: {str(exc)}. Please ensure the Input model inherits from BaseModel,\n"
191+
"and your payload adheres to the specified Input model structure.\n"
192+
f"Model={model}",
193+
)

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.