Repository navigation
fix: surface server detail and cause on connection failures #587
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
Open
vuanhphung
wants to merge
4
commits into
main
Choose a base branch
from
fix/issue-467-connection-failure-detail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c625ed7
fix: surface server detail and cause on connection failures
vuanhphung 454ea21
engineer-bot: address @mention on PR #587
peco-engineer-bot[bot] d9c01e4
Merge branch 'main' into fix/issue-467-connection-failure-detail
vuanhphung cc1e213
engineer-bot: address @mention on PR #587
peco-engineer-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { expect, AssertionError } from 'chai'; | ||
| import { DBSQLClient } from '../../lib'; | ||
| import { THTTPException } from '../../lib/connection/connections/ThriftHttpConnection'; | ||
|
|
||
| import config from './utils/config'; | ||
|
|
||
| const INVALID_TOKEN = 'dapi-invalid-e2e-token'; | ||
|
|
||
| // Regression for https://github.com/databricks/databricks-sql-nodejs/issues/467 — | ||
| // a rejected session open should carry the server's detail in `message`. | ||
| describe('Connection failure errors', () => { | ||
| it('Thrift: includes the server detail in the message of a rejected session open', async () => { | ||
| const client = new DBSQLClient(); | ||
| try { | ||
| await client.connect({ host: config.host, path: config.path, token: INVALID_TOKEN }); | ||
| await client.openSession(); | ||
| expect.fail('It should throw an error'); | ||
| } catch (error) { | ||
| if (error instanceof AssertionError) { | ||
| throw error; | ||
| } | ||
| expect(error).to.be.instanceOf(THTTPException); | ||
| const { message, statusCode } = error as THTTPException; | ||
| expect(statusCode).to.be.oneOf([401, 403]); | ||
| expect(message.startsWith(`Received a response with a bad HTTP status code: ${statusCode}: `)).to.equal(true); | ||
| expect(message.toLowerCase()).to.include('token'); | ||
| expect(message).to.not.include(INVALID_TOKEN); | ||
| } finally { | ||
| await client.close(); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { expect, AssertionError } from 'chai'; | ||
| import { DBSQLClient } from '../../../lib'; | ||
| import AuthenticationError from '../../../lib/errors/AuthenticationError'; | ||
| import { ConnectionOptions } from '../../../lib/contracts/IDBSQLClient'; | ||
| import { InternalConnectionOptions } from '../../../lib/contracts/InternalConnectionOptions'; | ||
| import { tryGetKernelNative } from '../../../lib/kernel/KernelNativeLoader'; | ||
| import config from '../utils/config'; | ||
|
|
||
| const INVALID_TOKEN = 'dapi-invalid-e2e-token'; | ||
|
|
||
| // Regression for https://github.com/databricks/databricks-sql-nodejs/issues/467 — | ||
| // a rejected kernel session open should keep the underlying error as `cause`. | ||
| describe('kernel connection failure errors', function suite() { | ||
| this.timeout(60_000); | ||
|
|
||
| if (tryGetKernelNative() === undefined) { | ||
| it.skip('kernel native binding not available on this platform'); | ||
| return; | ||
| } | ||
|
|
||
| it('keeps the server detail in the message and the binding error as cause', async () => { | ||
| const client = new DBSQLClient(); | ||
| try { | ||
| await client.connect({ | ||
| host: config.host, | ||
| path: config.path, | ||
| token: INVALID_TOKEN, | ||
| useKernel: true, | ||
| } as ConnectionOptions & InternalConnectionOptions); | ||
| await client.openSession(); | ||
| expect.fail('It should throw an error'); | ||
| } catch (error) { | ||
| if (error instanceof AssertionError) { | ||
| throw error; | ||
| } | ||
| expect(error).to.be.instanceOf(AuthenticationError); | ||
| const { message, cause } = error as AuthenticationError & { cause?: unknown }; | ||
| expect(message).to.match(/HTTP 40[13]/); | ||
| expect(message.toLowerCase()).to.include('token'); | ||
| expect(message).to.not.include(INVALID_TOKEN); | ||
| expect(cause).to.be.instanceOf(Error); | ||
| expect((cause as Error).message).to.not.include('__databricks_error__'); | ||
| } finally { | ||
| await client.close(); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🔵 Low —
getErrorDetailFromBodyonly decodes the firstMAX_ERROR_BODY_SCAN(4096) bytes before callingJSON.parse, even though the whole body (up to 64 KiB) is already inprefix. When a JSON error body is longer than 4 KiB (for example, one with a longdetailsarray or a stack trace), the truncated text doesn't parse, so the code falls through tonormalizeErrorDetail(text). The message then gets the raw JSON prefix ({"error_code":...,"message":...) instead of themessagefield. The PR description says the detail is the "JSONmessage, else plain text", and that doesn't hold for these bodies. RunningJSON.parseon the full buffered body and applying the 4096 cap only in the plain-text fallback would keep that contract, at no extra cost since the body is already in memory.