@steve31415/baselib 3.62.0 → 3.62.2

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/log-core.js CHANGED
@@ -14,8 +14,8 @@ const CODE_MAX = 100;
14
14
  /** An Error's `code` property when it is a primitive worth a column: a
15
15
  * string (capped) or a finite number. Anything else is dropped, since an
16
16
  * object there would mint `meta.error.code.*` keys from data. */
17
- function errorCode(err) {
18
- const code = err.code;
17
+ function errorCode(err, key = 'code') {
18
+ const code = readProp(err, key);
19
19
  if (typeof code === 'string')
20
20
  return truncate(code, CODE_MAX);
21
21
  if (typeof code === 'number' && Number.isFinite(code))
@@ -57,8 +57,67 @@ export function serializeError(err) {
57
57
  }
58
58
  return out;
59
59
  }
60
+ if (typeof err === 'object' && err !== null)
61
+ return serializeNonErrorObject(err);
60
62
  return { name: 'NonError', message: truncate(String(err), 2000) };
61
63
  }
64
+ /** A property read that a throwing getter cannot turn into a logging failure. */
65
+ function readProp(o, key) {
66
+ try {
67
+ return o[key];
68
+ }
69
+ catch {
70
+ return undefined;
71
+ }
72
+ }
73
+ function constructorName(o) {
74
+ const name = readProp(o, 'constructor')?.name;
75
+ return typeof name === 'string' && name !== '' && name !== 'Object' ? name : undefined;
76
+ }
77
+ /** A thrown or rejected object that is not an Error. The common case is an
78
+ * event: puppeteer-core's connect() rejects with the ws library's
79
+ * ErrorEvent, whose `type`, `message` and `error` are prototype getters, so
80
+ * String() gives "[object Object]" and JSON "{}" — which hid a Cloudflare
81
+ * 401 (radar task 6262f4fb, 2026-11-08). Read the conventional fields
82
+ * directly; fall back to JSON, then to the constructor's name. The name
83
+ * stays 'NonError' so patterns keyed on it keep matching. */
84
+ function serializeNonErrorObject(o) {
85
+ const ctor = constructorName(o);
86
+ const message = readProp(o, 'message');
87
+ const type = readProp(o, 'type');
88
+ let text;
89
+ if (typeof message === 'string' && message !== '') {
90
+ const label = ctor === undefined ? '' : typeof type === 'string' && type !== '' ? `${ctor} (${type}): ` : `${ctor}: `;
91
+ text = label + message;
92
+ }
93
+ else {
94
+ let json;
95
+ try {
96
+ json = JSON.stringify(o);
97
+ }
98
+ catch {
99
+ // circular or a throwing toJSON: fall through
100
+ }
101
+ if (typeof json === 'string' && json !== '{}')
102
+ text = json;
103
+ else if (ctor !== undefined)
104
+ text = `${ctor} {}`;
105
+ else
106
+ text = json ?? '{}';
107
+ }
108
+ const out = { name: 'NonError', message: truncate(text, 2000) };
109
+ const code = errorCode(o) ?? errorCode(o, 'status');
110
+ if (code !== undefined)
111
+ out.code = code;
112
+ const inner = readProp(o, 'error');
113
+ if (inner instanceof Error) {
114
+ out.cause = { name: inner.name, message: inner.message };
115
+ const innerCode = errorCode(inner);
116
+ if (innerCode !== undefined)
117
+ out.cause.code = innerCode;
118
+ }
119
+ return out;
120
+ }
62
121
  export function truncate(s, max) {
63
122
  return s.length <= max ? s : s.slice(0, max) + `…[+${s.length - max}]`;
64
123
  }
@@ -2,7 +2,7 @@ import type { Runner } from '../deploy/types.js';
2
2
  import { type CliIo } from './cli.js';
3
3
  export declare const AXIOM_QUERY_URL = "https://api.axiom.co/v1/datasets/_apl?format=legacy";
4
4
  export declare const QUERY_TOKEN_SECRET = "shared--axiom-query-token";
5
- export declare const USAGE = "usage: pw-logs [options] [APL tail]\nQuery the fleet's Axiom logs (query-only token from Secret Manager).\n\n -d, --dataset <name> apps (default) | platform | rum\n -a, --app <name> app filter; default: the enclosing repo's deploy.config.json; \"all\" for none\n -l, --level <level> debug | info | warn | error; add \"+\" for that level and above (warn+)\n -s, --since <when> window start: duration back from now (30m, 6h, 3d) or timestamp (default 1h)\n -u, --until <when> window end, same forms (default now)\n -n, --limit <n> rows to return (default 200); events are the newest, printed oldest first\n --json print events (or aggregation rows) as a JSON array\n --all text mode: show every field (batch ids, full build_id)\n --apl print the query that would run and exit\n -h, --help\n\nThe tail is appended to the generated pipeline. The newest-first ordering\nis added only when the tail just filters or reshapes events (where, extend,\nproject-away/keep/rename, mv-expand, parse); a summarize, project, order or\ntake stage of your own decides the order. The limit always applies.\nExamples:\n pw-logs -l error -s 6h\n pw-logs -a chime \"where meta.user == 'x' | where message has 'sync'\"\n pw-logs -a all -l warn+ -s 24h \"summarize n=count() by app, message\"\n pw-logs -d platform -s 3d \"where severity != 'INFO'\"\nFields: apps = app, level, message, source, build_id, meta.* (a map: query\nsub-keys with dot notation, cast for summarize by \u2014 tostring(meta.user));\nplatform = service, severity, text, revision; rum = app, metric, value,\nrating, path, build_id.";
5
+ export declare const USAGE = "usage: pw-logs [options] [APL tail]\nQuery the fleet's Axiom logs (query-only token from Secret Manager).\n\n -d, --dataset <name> apps (default) | platform | rum\n -a, --app <name> app filter; default: the enclosing repo's deploy.config.json for\n apps/rum (\"all\" for none); platform has no default \u2014 it is keyed\n by GCP service name, not app, and a Cloud Run Job's service (e.g.\n radar-cf-probe, corpus-build) rarely equals its owning app's repo\n name, so pass -a explicitly there or you get every service\n -l, --level <level> debug | info | warn | error; add \"+\" for that level and above (warn+)\n -s, --since <when> window start: duration back from now (30m, 6h, 3d) or timestamp (default 1h)\n -u, --until <when> window end, same forms (default now)\n -n, --limit <n> rows to return (default 200); events are the newest, printed oldest first\n --json print events (or aggregation rows) as a JSON array\n --all text mode: show every field (batch ids, full build_id)\n --apl print the query that would run and exit\n -h, --help\n\nThe tail is appended to the generated pipeline. The newest-first ordering\nis added only when the tail just filters or reshapes events (where, extend,\nproject-away/keep/rename, mv-expand, parse); a summarize, project, order or\ntake stage of your own decides the order. The limit always applies.\nExamples:\n pw-logs -l error -s 6h\n pw-logs -a chime \"where meta.user == 'x' | where message has 'sync'\"\n pw-logs -a all -l warn+ -s 24h \"summarize n=count() by app, message\"\n pw-logs -d platform -s 3d \"where severity != 'INFO'\"\nFields: apps = app, level, message, source, build_id, meta.* (a map: query\nsub-keys with dot notation, cast for summarize by \u2014 tostring(meta.user));\nplatform = service, severity, text, revision; rum = app, metric, value,\nrating, path, build_id.";
6
6
  type Fields = Record<string, unknown>;
7
7
  interface DatasetSpec {
8
8
  appField: string;
package/dist/ops/logs.js CHANGED
@@ -23,7 +23,11 @@ export const USAGE = `usage: pw-logs [options] [APL tail]
23
23
  Query the fleet's Axiom logs (query-only token from Secret Manager).
24
24
 
25
25
  -d, --dataset <name> apps (default) | platform | rum
26
- -a, --app <name> app filter; default: the enclosing repo's deploy.config.json; "all" for none
26
+ -a, --app <name> app filter; default: the enclosing repo's deploy.config.json for
27
+ apps/rum ("all" for none); platform has no default — it is keyed
28
+ by GCP service name, not app, and a Cloud Run Job's service (e.g.
29
+ radar-cf-probe, corpus-build) rarely equals its owning app's repo
30
+ name, so pass -a explicitly there or you get every service
27
31
  -l, --level <level> debug | info | warn | error; add "+" for that level and above (warn+)
28
32
  -s, --since <when> window start: duration back from now (30m, 6h, 3d) or timestamp (default ${DEFAULT_SINCE})
29
33
  -u, --until <when> window end, same forms (default now)
@@ -245,7 +249,20 @@ export async function runLogs(options) {
245
249
  const limit = Number(v.limit);
246
250
  if (!Number.isInteger(limit) || limit < 1)
247
251
  throw new Error(`--limit must be a positive integer, got ${v.limit}`);
248
- let app = v.app ?? appConfig?.app;
252
+ // The enclosing repo's app name is only a sensible default when the
253
+ // dataset's own app-like field is literally named `app` (apps, rum).
254
+ // `platform` keys events by `service` — a GCP-level identifier that
255
+ // often diverges from the repo name (a Cloud Run Job such as
256
+ // `radar-cf-probe` or `corpus-build` belongs to an app's repo but
257
+ // never equals it) — so defaulting to the repo name there silently
258
+ // hides most of the dataset with no indication anything was filtered,
259
+ // unless the caller remembers --apl. Investigating from inside an
260
+ // app's repo with no explicit -a must see that app's own platform
261
+ // events too, which an exact-match default on the repo name would
262
+ // also miss. Explicit -a (any value, including a service/job name)
263
+ // always wins; only the implicit repo-name default is skipped.
264
+ const appsLikeDataset = datasetSpec(v.dataset).appField === 'app';
265
+ let app = v.app ?? (appsLikeDataset ? appConfig?.app : undefined);
249
266
  if (app === 'all')
250
267
  app = undefined;
251
268
  if (app !== undefined && !NAME.test(app))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.62.0",
3
+ "version": "3.62.2",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",