dolphindb 2.0.917 → 2.0.919

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browser.d.ts CHANGED
@@ -464,10 +464,12 @@ export interface DdbRpcOptions {
464
464
  parse_object?: boolean;
465
465
  }
466
466
  export declare class DdbConnectionError extends Error {
467
+ name: string;
467
468
  ddb: DDB;
468
469
  constructor(ddb: DDB, error_options?: ErrorOptions);
469
470
  }
470
471
  export declare class DdbDatabaseError extends Error {
472
+ name: string;
471
473
  ddb: DDB;
472
474
  type: DdbRpcType;
473
475
  options: DdbRpcOptions;
package/browser.js CHANGED
@@ -6,7 +6,7 @@ const { fromByteArray: buf2ipaddr } = ipaddrjs;
6
6
  import 'xshell/prototype.browser.js';
7
7
  import { blue, cyan, green, grey, magenta } from 'xshell/chalk.browser.js';
8
8
  import { concat, assert } from 'xshell/utils.browser.js';
9
- import { connect_websocket } from 'xshell/net.browser.js';
9
+ import { connect_websocket, WebSocketConnectionError } from 'xshell/net.browser.js';
10
10
  import { t } from './i18n/index.js';
11
11
  export var DdbForm;
12
12
  (function (DdbForm) {
@@ -2122,13 +2122,15 @@ export function int1282str(buffer, le = true) {
2122
2122
  }
2123
2123
  export const winsize = 10_0000;
2124
2124
  export class DdbConnectionError extends Error {
2125
+ name = 'DdbConnectionError';
2125
2126
  ddb;
2126
2127
  constructor(ddb, error_options) {
2127
- super(`${ddb.url} ${t('已断开')}`, error_options);
2128
+ super(`${ddb.url} ${t('已断开')}${error_options?.cause ? `. ${error_options.cause.message}` : ''}`, error_options);
2128
2129
  this.ddb = ddb;
2129
2130
  }
2130
2131
  }
2131
2132
  export class DdbDatabaseError extends Error {
2133
+ name = 'DdbDatabaseError';
2132
2134
  ddb;
2133
2135
  type;
2134
2136
  options;
@@ -2221,7 +2223,7 @@ export class DDB {
2221
2223
  if (options.streaming !== undefined)
2222
2224
  this.streaming = options.streaming;
2223
2225
  }
2224
- on_message(event) {
2226
+ on_message(buffer) {
2225
2227
  // 这里的实现一定会被 connect 中的实现覆盖
2226
2228
  }
2227
2229
  /** 建立实际的 WebSocket 连接到 URL 对应的 DolphinDB Establish a actual websocket connection to the DolphindB corresponding to the URL
@@ -2238,22 +2240,30 @@ export class DDB {
2238
2240
  await ptail;
2239
2241
  try {
2240
2242
  if (!this.connected) {
2241
- this.on_message = (event) => {
2243
+ this.on_message = buffer => {
2242
2244
  assert(false, t('这是在调用 this.rpc 之前默认的 on_message, 不应该被调用到,除非建立连接后 server 先推送了 message'));
2243
2245
  };
2244
2246
  this.presult = Promise.resolve(null);
2245
2247
  this.pnode_run_defined = false;
2246
- this.websocket = await connect_websocket(this.url, {
2247
- protocols: (() => {
2248
- if (this.streaming)
2249
- return 'streaming';
2250
- if (this.python)
2251
- return 'python';
2252
- })(),
2253
- on_message: (event) => {
2254
- this.on_message(event);
2255
- }
2256
- });
2248
+ try {
2249
+ this.websocket = await connect_websocket(this.url, {
2250
+ protocols: (() => {
2251
+ if (this.streaming)
2252
+ return 'streaming';
2253
+ if (this.python)
2254
+ return 'python';
2255
+ })(),
2256
+ on_message: (buffer) => {
2257
+ this.on_message(buffer);
2258
+ }
2259
+ });
2260
+ }
2261
+ catch (error) {
2262
+ if (error instanceof WebSocketConnectionError)
2263
+ throw new DdbConnectionError(this, { cause: error });
2264
+ else
2265
+ throw error;
2266
+ }
2257
2267
  if (this.streaming)
2258
2268
  await this.subscribe();
2259
2269
  else {
@@ -2390,7 +2400,7 @@ export class DDB {
2390
2400
  }
2391
2401
  catch { }
2392
2402
  // 临界区结束,只有一个 rpc 函数调用运行到这里,可以独占 this.on_message 然后写 WebSocket
2393
- this.on_message = ({ data: buffer }) => {
2403
+ this.on_message = (buffer) => {
2394
2404
  try {
2395
2405
  const buf = new Uint8Array(buffer);
2396
2406
  if (this.print_message_buffer)
@@ -2614,7 +2624,7 @@ export class DDB {
2614
2624
  segments: [],
2615
2625
  };
2616
2626
  // 先准备好收到 websocket message 的 callback
2617
- this.on_message = ({ data: buffer }) => {
2627
+ this.on_message = buffer => {
2618
2628
  let { streaming } = this;
2619
2629
  try {
2620
2630
  const dv = new DataView(buffer);