@saptools/cf-inspector 0.4.10 → 0.4.12

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DebuggerHandle, SessionStatus } from '@saptools/cf-debugger';
2
2
 
3
- type CfInspectorErrorCode = "INVALID_ARGUMENT" | "INVALID_BREAKPOINT" | "INVALID_REMOTE_ROOT" | "INVALID_EXPRESSION" | "INVALID_HIT_COUNT" | "INVALID_PAUSE_TYPE" | "BREAKPOINT_DID_NOT_BIND" | "INSPECTOR_DISCOVERY_FAILED" | "INSPECTOR_CONNECTION_FAILED" | "CDP_REQUEST_FAILED" | "BREAKPOINT_NOT_HIT" | "UNRELATED_PAUSE" | "UNRELATED_PAUSE_TIMEOUT" | "EVALUATION_FAILED" | "MISSING_TARGET" | "ABORTED";
3
+ type CfInspectorErrorCode = "INVALID_ARGUMENT" | "INVALID_BREAKPOINT" | "INVALID_REMOTE_ROOT" | "INVALID_EXPRESSION" | "SETUP_EVAL_FAILED" | "INVALID_HIT_COUNT" | "INVALID_PAUSE_TYPE" | "BREAKPOINT_DID_NOT_BIND" | "INSPECTOR_DISCOVERY_FAILED" | "INSPECTOR_CONNECTION_FAILED" | "CDP_REQUEST_FAILED" | "BREAKPOINT_NOT_HIT" | "UNRELATED_PAUSE" | "UNRELATED_PAUSE_TIMEOUT" | "EVALUATION_FAILED" | "MISSING_TARGET" | "ABORTED";
4
4
  declare class CfInspectorError extends Error {
5
5
  readonly code: CfInspectorErrorCode;
6
6
  readonly detail?: string;
@@ -265,6 +265,7 @@ declare function resume(session: InspectorSession): Promise<void>;
265
265
  declare function setPauseOnExceptions(session: InspectorSession, state: PauseOnExceptionsState): Promise<void>;
266
266
  declare function evaluateOnFrame(session: InspectorSession, callFrameId: string, expression: string): Promise<CdpEvalResult>;
267
267
  declare function evaluateGlobal(session: InspectorSession, expression: string): Promise<CdpEvalResult>;
268
+ declare function runSetupEvals(session: InspectorSession, expressions: readonly string[]): Promise<void>;
268
269
  declare function listScripts(session: InspectorSession): readonly ScriptInfo[];
269
270
  declare function validateExpression(session: InspectorSession, expression: string): Promise<void>;
270
271
  declare function getProperties(session: InspectorSession, objectId: string): Promise<readonly CdpProperty[]>;
@@ -344,4 +345,4 @@ interface OpenedTunnel {
344
345
  }
345
346
  declare function openCfTunnel(target: TunnelTarget): Promise<OpenedTunnel>;
346
347
 
347
- export { type BreakpointHandle, type BreakpointLocation, type CallFrameInfo, type CaptureSnapshotOptions, type CapturedExpression, CfInspectorError, type CfInspectorErrorCode, type DebuggerState, type ExceptionSnapshot, type FrameSnapshot, type InspectorConnectOptions, type InspectorSession, type InspectorTarget, type LogpointConditionOptions, type LogpointEvent, type LogpointStopReason, type LogpointStreamOptions, type LogpointStreamResult, type OpenedTunnel, type PauseEvent, type PauseOnExceptionsState, type RemoteRootSetting, type ResolvedLocation, type ScopeInfo, type ScopeSnapshot, type ScriptInfo, type SetBreakpointInput, type SnapshotCaptureResult, type SnapshotResult, type TunnelTarget, type VariableSnapshot, type WaitForPauseOptions, type WalkStackOptions, type WatchEvent, buildBreakpointUrlRegex, buildHitCountedCondition, buildLogpointCondition, captureException, captureSnapshot, connectInspector, discoverInspectorTargets, evaluateGlobal, evaluateOnFrame, fetchInspectorVersion, getProperties, listScripts, openCfTunnel, parseBreakpointSpec, parseRemoteRoot, removeBreakpoint, resume, setBreakpoint, setPauseOnExceptions, streamLogpoint, validateExpression, waitForPause, walkStack };
348
+ export { type BreakpointHandle, type BreakpointLocation, type CallFrameInfo, type CaptureSnapshotOptions, type CapturedExpression, CfInspectorError, type CfInspectorErrorCode, type DebuggerState, type ExceptionSnapshot, type FrameSnapshot, type InspectorConnectOptions, type InspectorSession, type InspectorTarget, type LogpointConditionOptions, type LogpointEvent, type LogpointStopReason, type LogpointStreamOptions, type LogpointStreamResult, type OpenedTunnel, type PauseEvent, type PauseOnExceptionsState, type RemoteRootSetting, type ResolvedLocation, type ScopeInfo, type ScopeSnapshot, type ScriptInfo, type SetBreakpointInput, type SnapshotCaptureResult, type SnapshotResult, type TunnelTarget, type VariableSnapshot, type WaitForPauseOptions, type WalkStackOptions, type WatchEvent, buildBreakpointUrlRegex, buildHitCountedCondition, buildLogpointCondition, captureException, captureSnapshot, connectInspector, discoverInspectorTargets, evaluateGlobal, evaluateOnFrame, fetchInspectorVersion, getProperties, listScripts, openCfTunnel, parseBreakpointSpec, parseRemoteRoot, removeBreakpoint, resume, runSetupEvals, setBreakpoint, setPauseOnExceptions, streamLogpoint, validateExpression, waitForPause, walkStack };
package/dist/index.js CHANGED
@@ -501,16 +501,39 @@ async function fetchJson(url, timeoutMs) {
501
501
  );
502
502
  });
503
503
  req.on("error", (err) => {
504
- reject(
505
- err instanceof CfInspectorError ? err : new CfInspectorError(
506
- "INSPECTOR_DISCOVERY_FAILED",
507
- `Inspector discovery at ${url} failed: ${err.message}`
508
- )
509
- );
504
+ reject(err instanceof CfInspectorError ? err : formatDiscoveryRequestError(url, err));
510
505
  });
511
506
  req.end();
512
507
  });
513
508
  }
509
+ function isNodeSystemError(err) {
510
+ return err instanceof Error;
511
+ }
512
+ function isConnectionRefusedOrUnreachable(code) {
513
+ return code === "ECONNREFUSED" || code === "ECONNRESET" || code === "ETIMEDOUT" || code === "EHOSTUNREACH" || code === "ENETUNREACH";
514
+ }
515
+ function formatEndpoint(url, err) {
516
+ if (typeof err.address === "string" && typeof err.port === "number") {
517
+ return `${err.address}:${err.port.toString()}`;
518
+ }
519
+ const parsed = new URL(url);
520
+ return parsed.host;
521
+ }
522
+ function formatDiscoveryRequestError(url, err) {
523
+ const detail = err instanceof Error ? err.message : String(err);
524
+ if (!isNodeSystemError(err) || !isConnectionRefusedOrUnreachable(err.code)) {
525
+ return new CfInspectorError(
526
+ "INSPECTOR_DISCOVERY_FAILED",
527
+ `Inspector discovery at ${url} failed: ${detail}`
528
+ );
529
+ }
530
+ const endpoint = formatEndpoint(url, err);
531
+ return new CfInspectorError(
532
+ "INSPECTOR_DISCOVERY_FAILED",
533
+ `Cannot reach Node inspector discovery at ${url}. Nothing is listening on ${endpoint}, or the inspector tunnel is stale/closed. Restart the local inspector or tunnel and retry. If this port came from cf-debugger, stop the stale session and start a fresh tunnel, or run cf-inspector with --app/--region/--org/--space so it can open a tunnel.`,
534
+ detail
535
+ );
536
+ }
514
537
  function parseJsonResponse(chunks) {
515
538
  const text = Buffer.concat(chunks).toString("utf8");
516
539
  return JSON.parse(text);
@@ -723,6 +746,20 @@ async function evaluateGlobal(session, expression) {
723
746
  silent: true
724
747
  });
725
748
  }
749
+ async function runSetupEvals(session, expressions) {
750
+ for (const expression of expressions) {
751
+ const result = await evaluateGlobal(session, expression);
752
+ if (result.exceptionDetails !== void 0) {
753
+ throw new CfInspectorError(
754
+ "SETUP_EVAL_FAILED",
755
+ exceptionDetailsMessage(result, "setup evaluation failed")
756
+ );
757
+ }
758
+ }
759
+ }
760
+ function exceptionDetailsMessage(result, fallback) {
761
+ return typeof result.exceptionDetails?.exception?.description === "string" ? result.exceptionDetails.exception.description : typeof result.exceptionDetails?.text === "string" ? result.exceptionDetails.text : fallback;
762
+ }
726
763
  function listScripts(session) {
727
764
  return [...session.scripts.values()];
728
765
  }
@@ -1939,6 +1976,7 @@ export {
1939
1976
  parseRemoteRoot,
1940
1977
  removeBreakpoint,
1941
1978
  resume,
1979
+ runSetupEvals,
1942
1980
  setBreakpoint,
1943
1981
  setPauseOnExceptions,
1944
1982
  streamLogpoint,