Unreadable error message #3363
labbedaine
started this conversation in
General
Replies: 1 comment
-
Hi, thank you for opening this discussion. The log you're seeing is the formatted version of the error. When you log an error using Logger, its key get formatted into a JSON-serializable object, which includes the stack trace. At runtime, both You can verify that this is the case with code similar to this: import { z, ZodError } from 'zod';
import { Logger } from '@aws-lambda-powertools/logger';
import { parser } from '@aws-lambda-powertools/parser/middleware';
import { ParseError } from '@aws-lambda-powertools/parser';
import middy from '@middy/core';
import type { Context } from 'aws-lambda';
const logger = new Logger({ logLevel: 'debug' });
export const handler = middy()
.use(
parser({
schema: z.object({
foo: z.string(),
}),
safeParse: true,
})
)
.handler(async (event) => {
if (event.success === false) {
logger.debug('event.error instanceof ParseError', {
instanceOf: event.error instanceof ParseError,
});
logger.debug('event.error.cause instanceof ZodError', {
instanceOf: event.error.cause instanceof ZodError,
});
}
return {
statusCode: 200,
body: JSON.stringify('Hello, World!'),
};
}); which will log these two debug logs (notice the
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I want to use powertools-lambda-ts in my project but I am facing an issue with capturing the errors when the parsing fails. I would expect an Object that I can use to return to the front-end however I can only access the stack trace. I am sure I am missing something but I don't know what.
logger.error('Error parsing event', { event: event.error });
Thanks for the support!
Beta Was this translation helpful? Give feedback.
All reactions