-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
improve migration transform failure message and stacktrace #102478
improve migration transform failure message and stacktrace #102478
Conversation
expect(stackLines[0]).toEqual(`Error: Migration function for version 8.0.0 threw an error`); | ||
expect(stackLines[stackLength - 2]).toEqual(`Caused by:`); | ||
expect(stackLines[stackLength - 1]).toEqual(`some stack trace`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserting against a stack trace is always fun.
const appendCauseStack = (error: Error, cause: Error) => { | ||
error.stack = (error.stack ?? '') + `\nCaused by:\n${cause.stack ?? cause.message}`; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I choose to append the stack trace to the transform
error instead of just replacing the top error's stack with the cause's stack. It felt like this made the most sense, as that way we still have the info about both errors, in case of.
(Also this is how languages properly handling nested errors are usually doing it, at least regarding the output)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
const expectMatchOrder = (lines: string[], patterns: FindInOrderPattern[]) => { | ||
let lineIdx = 0; | ||
let patternIdx = 0; | ||
|
||
while (lineIdx < lines.length && patternIdx < patterns.length) { | ||
const line = lines[lineIdx]; | ||
const pattern = patterns[patternIdx]; | ||
if (lineMatch(line, pattern)) { | ||
patternIdx++; | ||
} | ||
lineIdx++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new interview exercice.
expectMatchOrder(errorLines, [ | ||
{ | ||
mode: 'equal', | ||
value: '- foo:3: Error: Migration function for version 7.14.0 threw an error', | ||
}, | ||
{ | ||
mode: 'contain', | ||
value: 'at transform', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best okay-ish approach I found to check the content of the error stack.
"Migrations failed. Reason: 1 corrupt saved object documents were found: a:b | ||
To allow migrations to proceed, please delete or fix these documents." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I did not handle singular/plural in the message, as it didn't really feel that important, but if we really want it, I could do it.
Pinging @elastic/kibana-core (Team:Core) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a small nit in the comments
} | ||
} | ||
|
||
const appendCauseStack = (error: Error, cause: Error) => { | ||
error.stack = (error.stack ?? '') + `\nCaused by:\n${cause.stack ?? cause.message}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is no error.stack
we'd be starting with an empty new line \nCaused by:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, OTOH until this function is extracted from this file, I think this is alright, as the only call to appendCauseStack
is performed inside the constructor after the call to super
, so we shouldn't really encounter a situation where the stack is empty (and we got unit tests to assert that)
const appendCauseStack = (error: Error, cause: Error) => { | ||
error.stack = (error.stack ?? '') + `\nCaused by:\n${cause.stack ?? cause.message}`; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
…c-transform-failure-cause
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
…02478) * improve migration failure message and stacktrace * remove console.log * fix unit tests * fix integration tests * fix more unit tests
Summary
Fix #102336
Example of new stacktrace:
Checklist