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(cactus-common): add createRuntimeErrorWithCause() & newRex() #1702

Closed
m-courtin opened this issue Dec 29, 2021 · 5 comments · Fixed by #1707
Closed

feat(cactus-common): add createRuntimeErrorWithCause() & newRex() #1702

m-courtin opened this issue Dec 29, 2021 · 5 comments · Fixed by #1707
Assignees
Labels
Developer_Experience enhancement New feature or request P2 Priority 2: High
Milestone

Comments

@m-courtin
Copy link
Contributor

m-courtin commented Dec 29, 2021

Describe the bug

In multiple places in the code within a catch block the .message and .stack is directly getting accessed without any checks. As possibly all things can be thrown in TypeScript / JavaScript (even undefined or null etc.) and not only Error objects. Therefore it needs to be validated first if .message respective .stack are existing before they are getting accessed. Furthermore a fallback should be implemented in case the thrown objects are no regular Error objects and not providing the requested properties or the stringify of the .stack for example is failing due to hierarchy depth etc.

@m-courtin m-courtin added the bug Something isn't working label Dec 29, 2021
@petermetz
Copy link
Contributor

petermetz commented Dec 29, 2021

@m-courtin FYI: Here is a related issue #1129 and the PR corresponding to said issue that @Leeyoungone has been working on for some time: #1384

Also adding this issue to this epic because they are overlapping a bit: #1378

@Leeyoungone
Copy link
Contributor

@petermetz Thanks for the ping and letting me know. Do you happen to have an example of

needs to be validated first if .message respective .stack are existing before they are getting accessed.

Do you happen to have any code examples that validate the .message and .stack before they are getting accessed?

@m-courtin
Copy link
Contributor Author

@petermetz: Thank you very much for the heads-up about the PR @Leeyoungone is working on. So I will only include the basic functionality into my PR that @Leeyoungone can use it in her PR

m-courtin added a commit to m-courtin/cactus that referenced this issue Dec 30, 2021
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 3, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 4, 2022
Introduce public getExceptionStack and getExceptionMessage functions
with corresponding unit tests and include the new log-helper into
api-server as usage example

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 4, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 4, 2022
Fix update unit tests for generic exception handling to match new log
helper returns

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 4, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 5, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 7, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
@petermetz
Copy link
Contributor

Do you happen to have any code examples that validate the .message and .stack before they are getting accessed?

@Leeyoungone Yup, this is it:

if (ex instanceof Error) {
// ex has .message and .stack
}

@Leeyoungone
Copy link
Contributor

@petermetz Ah cool cool! thank you :)

m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 12, 2022
Integrate custom exception handling and additionally integrate exception
handling for nested / cascaded exceptions

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 12, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 13, 2022
Extend the generic exception stack handling functionality to also
analyze / process custom exceptions

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 13, 2022
Adapt the unit tests to match to the extended exception stack handling

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Leeyoungone pushed a commit to Leeyoungone/cactus that referenced this issue Jan 13, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 2, 2022
Incorporate review comments and enhancing functional documentaion and
applying new Exception-Helper functionality to api-server as demo for
all other code

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 3, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 3, 2022
Incorporate review comments and enhancing functional documentaion and
applying new Exception-Helper functionality to api-server as demo for
all other code

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 3, 2022
Add detail documentaion to functionality newRuntimeError in
exception-helper

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 3, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 4, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 8, 2022
Fix getExceptionMessageInfo() function in exception-helper and add some
documentation to logger.exception

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 8, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 8, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 9, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 10, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 11, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
petermetz pushed a commit to m-courtin/cactus that referenced this issue Feb 23, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Feb 25, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Mar 1, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
m-courtin added a commit to m-courtin/cactus that referenced this issue Mar 2, 2022
Introduce a log helper with static functions to get exception message /
exception stack whatever is thrown or provided.

Closes: hyperledger-cacti#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
@petermetz petermetz assigned petermetz and unassigned m-courtin Sep 19, 2023
@petermetz petermetz added enhancement New feature or request Developer_Experience P2 Priority 2: High and removed bug Something isn't working labels Sep 19, 2023
@petermetz petermetz added this to the v2.0.0 milestone Sep 19, 2023
@petermetz petermetz changed the title fix: Exception / error handling directly accessing .stack and .message feat(cactus-common): add createRuntimeErrorWithCause() & newRex() Sep 19, 2023
@github-project-automation github-project-automation bot moved this from In review to Done in Cacti_Scrum_Project_v2_Release Sep 19, 2023
sandeepnRES pushed a commit to sandeepnRES/cacti that referenced this issue Dec 21, 2023
Utility functions to conveniently re-throw excpetions typed as unknown
by their catch block (which is the default since Typescript v4.4).

Example usage can and much more documentation can be seen here:

`packages/cactus-common/src/main/typescript/exception/create-runtime-error-with-cause.ts`
and here
`packages/cactus-common/src/test/typescript/unit/exception/create-runtime-error-with-cause.test.ts`

Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com>

Closes: hyperledger-cacti#1702

[skip ci]

Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer_Experience enhancement New feature or request P2 Priority 2: High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants