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

feat(types): resolves error types incompability with imt-blueprint #16

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

vokrik
Copy link
Contributor

@vokrik vokrik commented Oct 17, 2024

https://make.atlassian.net/browse/CDM-12048

both proto and imt-bluperint override global error in incompatible ways. When both packages are included in a single project, you get a typescript error.

See comments inline for more explanation

@vokrik vokrik requested a review from a team as a code owner October 17, 2024 11:34
@make-coverage
Copy link

make-coverage bot commented Oct 17, 2024

Unit Test Coverage Report

Metric master CDM-12048-fix-types Status
Statements 85.33% 85.54% 🌲
Branches 44.94% 46.15% 🌲
Functions 65.45% 66.07% 🌲

Copy link

github-actions bot commented Oct 17, 2024

Messages
Your PR title & description are valid

Generated 18. 10. 2024 12:55:04 GMT+2 for 5e72d2e

@@ -25,10 +25,12 @@
"url": "https://github.com/integromat/imt-proto"
},
"license": "MIT",
"dependencies": {
"@types/request": "^2.48.12"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The request type is part of the interface of the Hook. By not including the type in the dependencies, you get typescript error. This issue haven't surfaced yet, because most of the repositories depend on something (like express) that bring in this dependency. But by using the package in imt-blueprint it surfaced

@@ -9,20 +9,23 @@ declare global {
bundle?: Bundle;
suberrors?: Error[];
external?: any;

imtExceptionHash?: string; // moved from imt-blueprint - it is the same thing as hash, it is just a historical inconsistency
imtInternalError?: Error; // moved from imt-blueprint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically this is used just in blueprint I guess to distinguish distinguish: "file not loaded" from node and "Failed to load package" that is the actual intent. Imho it is a bad idea and if I was designing it, I would just translate the error to the "Failed to load package" and add the "file not loaded" to the "cause", but decided to keep it here for backwards compatibilty

@vokrik vokrik force-pushed the CDM-12048-fix-types branch from 7f00e56 to f2bbf8b Compare October 17, 2024 11:46
toJSON() {
return Object.assign(super.toJSON(), this);
toJSON(): ErrorJSON {
return { ...this, ...super.toJSON() };
Copy link
Contributor Author

@vokrik vokrik Oct 17, 2024

Choose a reason for hiding this comment

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

Imho this should be first and I would bet it caused unexpected behaviour on serialized properties. You called super.toJSON() that would for example serialize the suberrors, but then this object assign over them unserialized.

@@ -453,7 +468,22 @@ Object.defineProperty(Error.prototype, 'toJSON', {
if (this.bundle != null) json.bundle = this.bundle;
if (Array.isArray(this.suberrors)) json.suberrors = this.suberrors.map((item: Error) => item.toJSON());
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 wonder if this is even necessary, cause I would expect the JSON.stringify() to actually go through all of the items in the array and call toJSON on them. I wonder why we are doing it manually here, but @skvelymake taught me not to touch such kind of things here :D

@@ -45,6 +45,7 @@ declare global {
var IMTRPC: typeof publicApi.IMTRPC;
var IMTFeeder: typeof publicApi.IMTFeeder;
var IMTTransformer: typeof publicApi.IMTTransformer;
var IMTHITL: typeof publicApi.IMTHITL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was for some reason missing, but the blueprint has this line of code that depends on this in global:

Seems like we forgot to add it when doing some refactoring

       if (klass.prototype instanceof IMTHITL)

message: 'Type message.',
stack: ee.stack,
},
imtExceptionHash: 'im-hash',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not super happy about repeating this one. I was thinking about not serializing it and keeping just the hash, but I guess something in datadog could depend on it for projects that assign this value.

@vokrik vokrik force-pushed the CDM-12048-fix-types branch from cb05b04 to f1fa79b Compare October 17, 2024 11:56
@@ -9,7 +9,7 @@
"integromat",
"imt"
],
"version": "2.4.0",
"version": "2.5.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless you see something here that would require a Major version bump. To me seems like minor

Copy link
Collaborator

@skvelymake skvelymake left a comment

Choose a reason for hiding this comment

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

I like the changes.

Unfortunatelly I feel there will be more of these...

src/error.ts Outdated Show resolved Hide resolved
@@ -9,7 +9,7 @@
"integromat",
"imt"
],
"version": "2.4.0",
"version": "2.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I tend to do version bump in a separate commit, but if you are going to release the library I think that's fine.

Co-authored-by: skvelymake <112627159+skvelymake@users.noreply.github.com>
@vokrik vokrik merged commit 63bebd8 into master Oct 18, 2024
3 checks passed
@vokrik vokrik deleted the CDM-12048-fix-types branch October 18, 2024 10:59
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