-
Notifications
You must be signed in to change notification settings - Fork 155
Feature request: type Error | LogAttributes
is not excepted as extra input
#1111
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
Comments
another option would be this type: But trying around a bit I found the solution, that is even shorter and does exactly the same: If
both will have an error property: |
Hi @ghdoergeloh, thank you for reporting this. Please allow us some time to go through the repro example and return to you with a reply. |
Could you tell us on why do you want to pass the Logger assumes that While we can throw anything, but that is not a recommended practice. |
yeah, that's right, but i cannot guarantee that a lib i am using is alsways throwing only errors and if it is something different (e.g. jest overwrites the default Error object, which causes "instanceof Error" to fail - see jestjs/jest#2549) then I won't get the complete information about the error in the log. So I don't want to throw it, I want to catch and log it. |
Would if work if you reconstruct the error object like this?
I understand that this will be more lengthy. But I'm reluctant to widen the interface because other tools throw non-error object. If we accept Also, the type From another perspective, we can say that the extra value of @saragerion What's your thought on this? |
As discussed above, using {
"level": "ERROR",
"message": "This is the first error",
"service": "serverlessAirline",
"timestamp": "2021-12-12T22:12:39.345Z",
"xray_trace_id": "abcdef123456abcdef123456abcdef123456",
"error": {
"name": "Error",
"location": "/path/to/my/source-code/my-service/handler.ts:18",
"message": "Unexpected error #1",
"stack": "Error: Unexpected error #1 at lambdaHandler (/path/to/my/source-code/my-service/handler.ts:18:11) at Object.<anonymous> (/path/to/my/source-code/my-service/handler.ts:35:1) at Module._compile (node:internal/modules/cjs/loader:1108:14) at Module.m._compile (/path/to/my/source-code/node_modules/ts-node/src/index.ts:1371:23) at Module._extensions..js (node:internal/modules/cjs/loader:1137:10) at Object.require.extensions.<computed> [as .ts] (/path/to/my/source-code/node_modules/ts-node/src/index.ts:1374:12) at Module.load (node:internal/modules/cjs/loader:973:32) at Function.Module._load (node:internal/modules/cjs/loader:813:14) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) at main (/path/to/my/source-code/node_modules/ts-node/src/bin.ts:331:12)"
}
} Furthermore, it's also possible to customize the key used for the error by using In regards to custom errors, as long as these errors extend the import { Logger, injectLambdaContext } from "@aws-lambda-powertools/logger";
import middy from "@middy/core";
const logger = new Logger({ serviceName: "someName" });
class MyCustomError extends Error {
public foo: string;
constructor (message: string) {
super(message)
this.foo = "bar"
}
}
export const handler = middy(async () => {
try {
throw new MyCustomError("error");
} catch (err) {
if (err instanceof MyCustomError) {
logger.error("some error", err);
}
}
}).use(injectLambdaContext(logger)); At the moment we are not going to widen the type for errors as I'm inclined to consider this more akin to a feature request rather than a bug. I'm going to close this issue, however I'm open to revisit the decision in case there's enough customer demand. |
|
Error | LogAttributes
is not excepted as extra inputError | LogAttributes
is not excepted as extra input
@dreamorosi to throw in my 2p the type definition does seem a little weird and should probably be more like
It seems a little confusing that elsewhere you can pass in as many additional objects as you like to help with debugging, including with |
Bug description
I would like to log a error inside a catch blog. In the newest version of Typescript a catched "Error" has the type unknown, because it could be anything. So I decided to use the following code:
but the type is not compatible.
Expected Behavior
The type should be accepted, because both variants are okay:
Current Behavior
The typescript compiler gives the following Message:
Possible Solution
Changing the typedeclaration to the following worked:
Steps to Reproduce
Environment
Related issues, RFCs
The text was updated successfully, but these errors were encountered: