• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dialoguedb / client-nodejs / 29514741471

16 Jul 2026 04:14PM UTC coverage: 84.188%. First build
29514741471

Pull #96

github

web-flow
Merge aed831731 into 21ee76827
Pull Request #96: Add isNotFoundError and improve getDialogue error handling

992 of 1168 branches covered (84.93%)

Branch coverage included in aggregate %.

13 of 14 new or added lines in 4 files covered. (92.86%)

1127 of 1349 relevant lines covered (83.54%)

38.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/cli/shared.ts
1
import { DialogueDBError } from "../errors";
×
2
import { getDialogue } from "../methods/getDialogue";
×
3

4
export function parseJSON(label: string, raw: string): unknown {
×
5
  try {
×
6
    return JSON.parse(raw);
×
7
  } catch (e) {
8
    const message = e instanceof Error ? e.message : String(e);
×
9
    throw new Error(`--${label} is not valid JSON: ${message}`);
×
10
  }
11
}
12

13
export function parseCSV(raw: string): string[] {
×
14
  return raw
×
15
    .split(",")
16
    .map((s) => s.trim())
×
17
    .filter((s) => s.length > 0);
×
18
}
19

20
export function parseIntStrict(label: string, raw: string): number {
×
21
  const n = Number(raw);
×
22
  if (!Number.isInteger(n)) {
×
23
    throw new Error(`--${label} must be an integer, got "${raw}"`);
×
24
  }
25
  return n;
×
26
}
27

28
export async function readStdin(): Promise<string> {
×
29
  if (process.stdin.isTTY) {
×
30
    throw new Error(
×
31
      "--stdin was passed but stdin is a terminal (no piped input detected)"
32
    );
33
  }
34
  const chunks: Buffer[] = [];
×
35
  for await (const chunk of process.stdin) {
×
36
    chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
×
37
  }
38
  return Buffer.concat(chunks).toString("utf8");
×
39
}
40

41
/**
42
 * Loads a dialogue, or exits non-zero. A miss throws a DialogueDBError, which
43
 * withErrorHandler reports and exits on — so the CLI prints the namespace hint
44
 * and requestId rather than a bare "not found".
45
 */
46
export async function loadDialogueOrExit(id: string, namespace?: string) {
×
NEW
47
  return getDialogue({
×
48
    id,
49
    ...(namespace && { namespace }),
×
50
  });
51
}
52

53
export async function resolveContent(opts: {
×
54
  content?: string;
55
  stdin?: boolean;
56
}): Promise<string> {
57
  if (opts.stdin) return (await readStdin()).trimEnd();
×
58
  if (opts.content !== undefined) return opts.content;
×
59
  throw new Error("Provide --content <text> or --stdin");
×
60
}
61

62
export function output(value: unknown): void {
×
63
  process.stdout.write(JSON.stringify(value, null, 2) + "\n");
×
64
}
65

66
export function withErrorHandler<A extends unknown[]>(
×
67
  fn: (...args: A) => Promise<void>
68
) {
69
  return async (...args: A): Promise<void> => {
×
70
    try {
×
71
      await fn(...args);
×
72
    } catch (e) {
73
      if (e instanceof DialogueDBError) {
×
74
        process.stderr.write(
×
75
          JSON.stringify(
76
            {
77
              error: e.message,
78
              code: e.code,
79
              type: e.type,
80
              statusCode: e.statusCode,
81
              requestId: e.requestId,
82
              details: e.details,
83
            },
84
            null,
85
            2
86
          ) + "\n"
87
        );
88
      } else {
89
        process.stderr.write(`${e instanceof Error ? e.message : String(e)}\n`);
×
90
      }
91
      process.exit(1);
×
92
    }
93
  };
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc