@ultimat3/core 31.34.0 → 31.36.0
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/package.json +2 -2
- package/src/client-flight.ts +1 -1
- package/src/client-problem.ts +1 -1
- package/src/client-scope-error.ts +1 -1
- package/src/config-health.ts +1 -1
- package/src/context.ts +3 -3
- package/src/cursor.ts +1 -1
- package/src/env.ts +8 -4
- package/src/error-codes.ts +3 -1
- package/src/flight-gate.ts +1 -1
- package/src/generation-fence.ts +1 -1
- package/src/ids.ts +2 -2
- package/src/intl-cache.ts +1 -1
- package/src/lifecycle-errors.ts +1 -1
- package/src/lifecycle-readiness.ts +1 -1
- package/src/lifecycle.ts +3 -3
- package/src/metric-errors.ts +1 -1
- package/src/metric-names.ts +3 -2
- package/src/metric-registry.ts +6 -5
- package/src/metric-series.ts +1 -1
- package/src/metrics.ts +2 -2
- package/src/otlp.ts +6 -6
- package/src/record-envelope.ts +1 -1
- package/src/roles.ts +2 -1
- package/src/sampler.ts +2 -1
- package/src/seal.ts +1 -1
- package/src/service.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/core",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.36.0",
|
|
4
4
|
"description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
"test": "bun test"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@ultimat3/schema": "31.
|
|
57
|
+
"@ultimat3/schema": "31.36.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/src/client-flight.ts
CHANGED
|
@@ -359,7 +359,7 @@ function deadlineExpired(subject: string, deadlineMs: number): UltimateError {
|
|
|
359
359
|
return new UltimateError({
|
|
360
360
|
code: 'X_TIMEOUT',
|
|
361
361
|
cause: `${subject} was aborted after its client deadline of ${deadlineMs}ms`,
|
|
362
|
-
fix:
|
|
362
|
+
fix: `clientFlight({ deadlineMs: ${deadlineMs * 2} }) // a raised deadline at the call site — or find what answers that slowly: x doctor --json`,
|
|
363
363
|
meta: { subject, deadlineMs },
|
|
364
364
|
});
|
|
365
365
|
}
|
package/src/client-problem.ts
CHANGED
|
@@ -150,7 +150,7 @@ export function transportFailed(
|
|
|
150
150
|
return new UltimateError({
|
|
151
151
|
code: 'X_CLIENT_TRANSPORT_FAILED',
|
|
152
152
|
cause,
|
|
153
|
-
fix: '
|
|
153
|
+
fix: 'x doctor --json # checks the network and the gateway in front of the app; then retry — a write with no idempotencyKey may already have landed',
|
|
154
154
|
...(retry === undefined ? {} : { retry }),
|
|
155
155
|
meta: { ...meta, failure },
|
|
156
156
|
...(sourceError === undefined ? {} : { sourceError }),
|
|
@@ -12,7 +12,7 @@ export function scopeChanged(subject: string, issued: number, current: number):
|
|
|
12
12
|
return new UltimateError({
|
|
13
13
|
code: 'X_CLIENT_SCOPE_CHANGED',
|
|
14
14
|
cause: `${subject} was issued for client scope epoch ${issued} and the page is now at ${current}, so its answer belongs to the previous principal`,
|
|
15
|
-
fix: '
|
|
15
|
+
fix: 'isSuperseded(error) // from @ultimat3/core: true for this one — render nothing, discard the answer and read again',
|
|
16
16
|
meta: { subject, issued, current },
|
|
17
17
|
});
|
|
18
18
|
}
|
package/src/config-health.ts
CHANGED
|
@@ -75,7 +75,7 @@ export function assertReadinessMode(value: unknown): ReadinessMode {
|
|
|
75
75
|
throw new UltimateError({
|
|
76
76
|
code: 'X_CONFIG_INVALID',
|
|
77
77
|
cause: issue,
|
|
78
|
-
fix: "
|
|
78
|
+
fix: "health: { readiness: 'process' } // in app.config.ts — or 'dependencies', the default",
|
|
79
79
|
meta: { key: 'health.readiness' },
|
|
80
80
|
});
|
|
81
81
|
}
|
package/src/context.ts
CHANGED
|
@@ -238,7 +238,7 @@ export function useContext(): Ctx {
|
|
|
238
238
|
throw new UltimateError({
|
|
239
239
|
code: 'X_NO_CONTEXT',
|
|
240
240
|
cause: 'useContext() was called outside of runWithContext()',
|
|
241
|
-
fix: '
|
|
241
|
+
fix: 'runWithContext(ctxOf({ ... }), fn) // wrap the entry point in it',
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
return ctx;
|
|
@@ -424,7 +424,7 @@ export function useService<T>(name: string): T {
|
|
|
424
424
|
throw new UltimateError({
|
|
425
425
|
code: 'X_SERVICE_MISSING',
|
|
426
426
|
cause: `"${name}" is not on ctx.services (have: ${Object.keys(ctx.services).join(', ')})`,
|
|
427
|
-
fix: `
|
|
427
|
+
fix: `ctxOf({ services: { ${name} } }) // pass the service in`,
|
|
428
428
|
meta: { name },
|
|
429
429
|
});
|
|
430
430
|
}
|
|
@@ -437,7 +437,7 @@ export function throwIfAborted(ctx: Ctx = useContext()): void {
|
|
|
437
437
|
throw new UltimateError({
|
|
438
438
|
code: 'X_ABORTED',
|
|
439
439
|
cause: `request ${ctx.requestId} was aborted by the caller`,
|
|
440
|
-
fix: '
|
|
440
|
+
fix: 'throwIfAborted(ctx) // before expensive work — and make each vendor call with outbound({ url, vendor, dial, deadlineMs }) from @ultimat3/core/outbound, which hears ctx.signal: the caller is gone, so unwind instead of finishing',
|
|
441
441
|
meta: { requestId: ctx.requestId },
|
|
442
442
|
});
|
|
443
443
|
}
|
package/src/cursor.ts
CHANGED
|
@@ -27,7 +27,7 @@ export class CursorInvalidError extends UltimateError {
|
|
|
27
27
|
super({
|
|
28
28
|
code: 'X_CURSOR_INVALID',
|
|
29
29
|
cause: `cursor rejected: ${reason}`,
|
|
30
|
-
fix: 'drop the cursor and request the first page again
|
|
30
|
+
fix: 'after: null // drop the cursor and request the first page again',
|
|
31
31
|
meta: { reason },
|
|
32
32
|
});
|
|
33
33
|
}
|
package/src/env.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// discover six missing variables.
|
|
4
4
|
|
|
5
5
|
import { numeric } from '@ultimat3/schema';
|
|
6
|
-
import { describeValue } from './error-render';
|
|
6
|
+
import { describeValue, renderFixShellArg } from './error-render';
|
|
7
7
|
import { EnvMissingError } from './errors';
|
|
8
8
|
import { REDACTED, redactKeys } from './logger';
|
|
9
9
|
import { type Role, resolveRole } from './roles';
|
|
@@ -180,7 +180,9 @@ export function checkEnv(schema: EnvSchema, options?: EnvOptions): EnvCheckRepor
|
|
|
180
180
|
reason: 'missing',
|
|
181
181
|
expected: expectation(decl),
|
|
182
182
|
received: undefined,
|
|
183
|
-
fix:
|
|
183
|
+
fix:
|
|
184
|
+
decl.fix ??
|
|
185
|
+
`grep '^${renderFixShellArg(key, '<KEY>')}=' .env.example >> .env # then give it ${expectation(decl)}`,
|
|
184
186
|
});
|
|
185
187
|
} else {
|
|
186
188
|
values[key] = undefined;
|
|
@@ -197,7 +199,9 @@ export function checkEnv(schema: EnvSchema, options?: EnvOptions): EnvCheckRepor
|
|
|
197
199
|
reason: 'invalid',
|
|
198
200
|
expected: expectation(decl),
|
|
199
201
|
received: decl.secret === true ? '***' : raw,
|
|
200
|
-
fix:
|
|
202
|
+
fix:
|
|
203
|
+
decl.fix ??
|
|
204
|
+
`grep -n '^${renderFixShellArg(key, '<KEY>')}=' .env # the line to set to ${expectation(decl)}`,
|
|
201
205
|
});
|
|
202
206
|
}
|
|
203
207
|
|
|
@@ -239,7 +243,7 @@ export function defineEnv<const S extends EnvSchema>(schema: S, options?: EnvOpt
|
|
|
239
243
|
const keys = report.issues.map((issue) => issue.key).join(' ');
|
|
240
244
|
throw new EnvMissingError({
|
|
241
245
|
cause,
|
|
242
|
-
fix: `
|
|
246
|
+
fix: `x env check # each key to add to .env (copy .env.example): ${keys}`,
|
|
243
247
|
meta: { issues: described },
|
|
244
248
|
});
|
|
245
249
|
}
|
package/src/error-codes.ts
CHANGED
|
@@ -62,7 +62,9 @@ export function registerErrorCodes(codes: Readonly<Record<string, ErrorCodeDecla
|
|
|
62
62
|
throw new UltimateError({
|
|
63
63
|
code: 'X_ERROR_CODE_DUPLICATE',
|
|
64
64
|
cause: `already registered: ${duplicates.join(', ')}`,
|
|
65
|
-
|
|
65
|
+
// No code spliced in: this module is in every browser graph, and screening a value for the
|
|
66
|
+
// shell would pull the render helper in with it. The cause names the codes.
|
|
67
|
+
fix: 'git grep -n registerErrorCodes # rename one of the codes the cause names',
|
|
66
68
|
meta: { duplicates },
|
|
67
69
|
});
|
|
68
70
|
}
|
package/src/flight-gate.ts
CHANGED
|
@@ -140,7 +140,7 @@ export function gateOverloaded(state: FlightGateState): UltimateError {
|
|
|
140
140
|
return new UltimateError({
|
|
141
141
|
code: 'X_FLIGHT_GATE_OVERLOADED',
|
|
142
142
|
cause: `${state.active} of ${state.subject} are running at the ceiling of ${state.maxConcurrent} and ${state.queued} more are queued at the limit of ${state.maxQueued}`,
|
|
143
|
-
fix:
|
|
143
|
+
fix: `flightGate({ maxConcurrent: ${state.maxConcurrent * 2}, maxQueued: ${state.maxQueued * 2} }) // only if the box has the capacity the extra slots buy — or retry after the Retry-After header`,
|
|
144
144
|
meta: {
|
|
145
145
|
active: state.active,
|
|
146
146
|
queued: state.queued,
|
package/src/generation-fence.ts
CHANGED
|
@@ -46,7 +46,7 @@ function superseded(subject: string, issued: number, current: number): UltimateE
|
|
|
46
46
|
return new UltimateError({
|
|
47
47
|
code: 'X_SUPERSEDED',
|
|
48
48
|
cause: `${subject} was issued at generation ${issued} and the fence is now at ${current}, so this answer describes a world that no longer exists`,
|
|
49
|
-
fix: 'discard this answer and re-issue the work against
|
|
49
|
+
fix: 'fence.generation() // discard this answer and re-issue the work against it — whoever called bump() has already started the replacement',
|
|
50
50
|
meta: { subject, issued, current },
|
|
51
51
|
});
|
|
52
52
|
}
|
package/src/ids.ts
CHANGED
|
@@ -151,7 +151,7 @@ export function uuidTimestamp(id: string): Date {
|
|
|
151
151
|
// problem document, and the strings that arrive here wrong are session tokens and API keys
|
|
152
152
|
// as often as they are typos. The expected shape is the half that helps the reader.
|
|
153
153
|
cause: `expected a UUIDv7 (${UUID_SHAPE}), received ${describeValue(id)}`,
|
|
154
|
-
fix: '
|
|
154
|
+
fix: 'uuidV7() // from @ultimat3/core: generate ids with it',
|
|
155
155
|
meta: { received: describeValue(id) },
|
|
156
156
|
});
|
|
157
157
|
}
|
|
@@ -183,7 +183,7 @@ export function parseId<K extends string>(kind: K, value: unknown): Id<K> {
|
|
|
183
183
|
throw new UltimateError({
|
|
184
184
|
code: 'X_ID_INVALID',
|
|
185
185
|
cause: `expected a ${kind} UUIDv7 (${UUID_SHAPE}), received ${describeValue(value)}`,
|
|
186
|
-
fix: `
|
|
186
|
+
fix: `typedId<'${kind}'>() // pass an id it produced`,
|
|
187
187
|
// `received`, not `value`: `meta` rides into the problem document and the log line too, and
|
|
188
188
|
// redaction is by key — there is no key here that a redaction list could ever cover.
|
|
189
189
|
meta: { kind, received: describeValue(value) },
|
package/src/intl-cache.ts
CHANGED
|
@@ -65,7 +65,7 @@ export function localeInvalid(locale: string): UltimateError {
|
|
|
65
65
|
return new UltimateError({
|
|
66
66
|
code: 'X_LOCALE_INVALID',
|
|
67
67
|
cause: `${localeExcerpt(locale)} is not a well-formed BCP 47 language tag`,
|
|
68
|
-
fix: "pass a tag like 'en', 'en-GB' or 'de-DE'
|
|
68
|
+
fix: "Intl.DateTimeFormat.supportedLocalesOf([tag]) // screens a header-supplied value before a formatter — pass a tag like 'en', 'en-GB' or 'de-DE'",
|
|
69
69
|
// The raw tag, under a NAME. A `cause` is copied into the 400 body and into the log line by
|
|
70
70
|
// `@ultimat3/http`'s `toProblem`, and a logger redacts by key — so a caller's value spliced
|
|
71
71
|
// into prose has no key left to redact, which is the whole argument `describeValue` rests on.
|
package/src/lifecycle-errors.ts
CHANGED
|
@@ -27,7 +27,7 @@ export function lifecycleDrained(state: 'draining' | 'stopped'): UltimateError {
|
|
|
27
27
|
return new UltimateError({
|
|
28
28
|
code: 'X_LIFECYCLE_DRAINED',
|
|
29
29
|
cause: `this process is ${state} — its lifecycle has already drained, and a drain is terminal: one process, one lifecycle. A role marked ready now would bind a socket that answers 503 to every request, and drain() memoizes, so nothing would ever close it`,
|
|
30
|
-
fix: 'start every role BEFORE the first drain — a drained process is on its way out and is replaced, never reused
|
|
30
|
+
fix: 'resetLifecycle() // from @ultimat3/core, in a test: between the drain and the next start(). In a process, start every role BEFORE the first drain — a drained process is on its way out and is replaced, never reused',
|
|
31
31
|
meta: { state },
|
|
32
32
|
});
|
|
33
33
|
}
|
|
@@ -58,7 +58,7 @@ export function registerReadinessCheck(
|
|
|
58
58
|
throw new UltimateError({
|
|
59
59
|
code: 'X_READINESS_CHECK_DUPLICATE',
|
|
60
60
|
cause: `a readiness check named "${name}" is already registered (have: ${[...checks.keys()].join(', ')})`,
|
|
61
|
-
fix: `name the second check for what it actually probes
|
|
61
|
+
fix: `registerReadinessCheck('${name}-replica', check) // name the second check for what it actually probes — or hold the unregister the first registration returned and call it first`,
|
|
62
62
|
meta: { name },
|
|
63
63
|
});
|
|
64
64
|
}
|
package/src/lifecycle.ts
CHANGED
|
@@ -91,7 +91,7 @@ export function configureLifecycle(options: LifecycleOptions): void {
|
|
|
91
91
|
throw new UltimateError({
|
|
92
92
|
code: 'X_CONFIG_INVALID',
|
|
93
93
|
cause: issue,
|
|
94
|
-
fix: '
|
|
94
|
+
fix: 'configureLifecycle({ readinessGraceMs: 5_000 }) // or, in app.config.ts: drain: { readinessGraceMs: 5_000 }',
|
|
95
95
|
meta: { key: 'drain.readinessGraceMs' },
|
|
96
96
|
});
|
|
97
97
|
}
|
|
@@ -308,7 +308,7 @@ async function runPhase(phase: ShutdownPhase, reason: ShutdownReason): Promise<v
|
|
|
308
308
|
report('warn', 'X_SHUTDOWN_TIMEOUT', {
|
|
309
309
|
code: 'X_SHUTDOWN_TIMEOUT',
|
|
310
310
|
cause: `the "${registration.name}" shutdown hook (phase: ${phase}) was still running at the ${deadlineMs}ms drain deadline and has been ABANDONED — the process exits without it, so anything it had in flight may be incomplete`,
|
|
311
|
-
fix: `
|
|
311
|
+
fix: `drain: { deadlineMs: 600_000 } // in app.config.ts: a budget past the work this hook does, here a 10-minute job (configureLifecycle({ deadlineMs: 600_000 }) outside a framework boot) — and give the platform's kill timer at least as many seconds (x deploy --method helm sizes the chart's from it), or make the "${registration.name}" hook return once it has stopped accepting work rather than once it has finished`,
|
|
312
312
|
hook: registration.name,
|
|
313
313
|
phase,
|
|
314
314
|
});
|
|
@@ -341,7 +341,7 @@ async function runDrain(signal: string): Promise<void> {
|
|
|
341
341
|
report('warn', 'X_SHUTDOWN_TIMEOUT', {
|
|
342
342
|
code: 'X_SHUTDOWN_TIMEOUT',
|
|
343
343
|
cause: `${inflight} in-flight operations still running after ${deadlineMs}ms`,
|
|
344
|
-
fix: '
|
|
344
|
+
fix: 'drain: { deadlineMs: 600_000 } // in app.config.ts: a budget past the slowest handler, here a 10-minute one (configureLifecycle({ deadlineMs: 600_000 }) outside a framework boot) — and give the platform kill timer at least as many seconds, or shorten the handler',
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
|
package/src/metric-errors.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function finite(name: string, value: number): number {
|
|
|
24
24
|
if (!Number.isFinite(value)) {
|
|
25
25
|
throw new MetricValueInvalidError({
|
|
26
26
|
cause: `${name} was given ${String(value)}, which is not a finite number`,
|
|
27
|
-
fix: `guard the value at the call site
|
|
27
|
+
fix: `Number.isFinite(v) // guard the value at the call site before recording into ${name}`,
|
|
28
28
|
meta: { metric: name, received: String(value) },
|
|
29
29
|
});
|
|
30
30
|
}
|
package/src/metric-names.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// the 500-line ceiling `x verify`'s `filesize` step enforces, and because the two refusals are one
|
|
4
4
|
// rule asked of two things — the exposition format spells them identically.
|
|
5
5
|
|
|
6
|
+
import { renderFixShellArg } from './error-render';
|
|
6
7
|
import { type CodedErrorInit, UltimateError } from './errors';
|
|
7
8
|
import type { MetricAttributes } from './metrics-types';
|
|
8
9
|
|
|
@@ -37,7 +38,7 @@ export function assertMetricName(name: string): void {
|
|
|
37
38
|
if (METRIC_NAME_RE.test(name)) return;
|
|
38
39
|
throw new MetricNameInvalidError({
|
|
39
40
|
cause: `"${name}" is not lowercase snake_case matching ${METRIC_NAME_RE.source}`,
|
|
40
|
-
fix: `rename the instrument to lowercase snake_case, e.g. ${snake(name)}`,
|
|
41
|
+
fix: `git grep -n ${renderFixShellArg(name, '<the name the cause quotes>')} # rename the instrument to lowercase snake_case, e.g. ${snake(name)}`,
|
|
41
42
|
meta: { name },
|
|
42
43
|
});
|
|
43
44
|
}
|
|
@@ -61,7 +62,7 @@ export function assertLabelNames(metric: string, attributes: MetricAttributes):
|
|
|
61
62
|
if (METRIC_NAME_RE.test(label)) continue;
|
|
62
63
|
throw new MetricNameInvalidError({
|
|
63
64
|
cause: `${metric} was given the label "${label}", which is not lowercase snake_case matching ${METRIC_NAME_RE.source} — the exposition line it renders is one no scraper can parse, and one bad line drops the whole scrape`,
|
|
64
|
-
fix: `
|
|
65
|
+
fix: `{ ${snake(label)}: … } // the label renamed to lowercase snake_case, at the call site`,
|
|
65
66
|
meta: { metric, label },
|
|
66
67
|
});
|
|
67
68
|
}
|
package/src/metric-registry.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// refused at declaration (bounds, ceiling, a conflicting redeclaration) rather than at the first
|
|
3
3
|
// recording. `metric-series.ts` stores points under an instrument; `metrics.ts` is the public seam.
|
|
4
4
|
|
|
5
|
+
import { renderFixShellArg } from './error-render';
|
|
5
6
|
import { MetricCardinalityError } from './metric-errors';
|
|
6
7
|
import { assertMetricName, MetricNameInvalidError } from './metric-names';
|
|
7
8
|
import type {
|
|
@@ -67,7 +68,7 @@ function assertBounds(name: string, bounds: readonly number[] | undefined): void
|
|
|
67
68
|
);
|
|
68
69
|
throw new MetricNameInvalidError({
|
|
69
70
|
cause: `${name} declared bounds [${bounds.map((bound) => String(bound)).join(', ')}], which are not strictly ascending finite numbers — [${String(bad)}] is ${String(bounds[bad])}`,
|
|
70
|
-
fix: `
|
|
71
|
+
fix: `histogram('${name}', { bounds: [${repaired.join(', ')}] }) // sorted, duplicates dropped`,
|
|
71
72
|
meta: { metric: name, bounds: bounds.map((bound) => String(bound)), at: bad },
|
|
72
73
|
});
|
|
73
74
|
}
|
|
@@ -84,7 +85,7 @@ export function declare(
|
|
|
84
85
|
if (existing.descriptor.kind !== kind) {
|
|
85
86
|
throw new MetricNameInvalidError({
|
|
86
87
|
cause: `"${name}" is already declared as a ${existing.descriptor.kind}, redeclared as a ${kind}`,
|
|
87
|
-
fix: `rename one of the two instruments
|
|
88
|
+
fix: `git grep -n ${renderFixShellArg(name, '<the metric the cause names>')} # rename one of the two instruments — one metric name, one kind`,
|
|
88
89
|
meta: { name, declared: existing.descriptor.kind, requested: kind },
|
|
89
90
|
});
|
|
90
91
|
}
|
|
@@ -95,7 +96,7 @@ export function declare(
|
|
|
95
96
|
if (!Number.isInteger(maxSeries) || maxSeries < 1) {
|
|
96
97
|
throw new MetricCardinalityError({
|
|
97
98
|
cause: `${name} declared maxSeries ${String(maxSeries)}, which is not a positive integer`,
|
|
98
|
-
fix: `
|
|
99
|
+
fix: `{ maxSeries: ${DEFAULT_MAX_SERIES} } // a positive integer, in the ${kind}('${name}', …) declaration`,
|
|
99
100
|
meta: { metric: name, maxSeries: String(maxSeries) },
|
|
100
101
|
});
|
|
101
102
|
}
|
|
@@ -134,14 +135,14 @@ function assertSameDeclaration(
|
|
|
134
135
|
if (bounds !== undefined && !sameBounds(existing.bounds, bounds)) {
|
|
135
136
|
throw new MetricNameInvalidError({
|
|
136
137
|
cause: `"${name}" is already declared with bounds [${existing.bounds.join(', ')}] and is redeclared with [${bounds.join(', ')}]; the first declaration wins, so the second set would never be used`,
|
|
137
|
-
fix: `
|
|
138
|
+
fix: `git grep -n ${renderFixShellArg(name, '<the metric the cause names>')} # declare it once and export the handle — import it where you record — or give the second instrument its own name`,
|
|
138
139
|
meta: { name, declared: existing.bounds.join(','), requested: bounds.join(',') },
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
if (observe !== undefined && observe !== existing.observe) {
|
|
142
143
|
throw new MetricNameInvalidError({
|
|
143
144
|
cause: `"${name}" is already declared with an observe() callback and is redeclared with a different one; the first declaration wins, so the second callback would never be read`,
|
|
144
|
-
fix: `
|
|
145
|
+
fix: `git grep -n ${renderFixShellArg(name, '<the metric the cause names>')} # declare it once and export the handle — import it where you read — or give the second gauge its own name`,
|
|
145
146
|
meta: { name },
|
|
146
147
|
});
|
|
147
148
|
}
|
package/src/metric-series.ts
CHANGED
|
@@ -66,7 +66,7 @@ function reportOverflow(instrument: Instrument): void {
|
|
|
66
66
|
const { name, kind } = instrument.descriptor;
|
|
67
67
|
const error = new MetricCardinalityError({
|
|
68
68
|
cause: `${name} reached its ceiling of ${instrument.maxSeries} label set(s); every further label set folds into one ${OVERFLOW_ATTRIBUTE}="true" series`,
|
|
69
|
-
fix: `drop the unbounded label from
|
|
69
|
+
fix: `{ maxSeries: ${instrument.maxSeries * 2} } // raised deliberately in ${kind}('${name}', …) — or drop the unbounded label from its call site (an id, a path, an email is never a label)`,
|
|
70
70
|
meta: { metric: name, maxSeries: instrument.maxSeries },
|
|
71
71
|
});
|
|
72
72
|
logger.error(error.format(), { code: error.code, metric: name });
|
package/src/metrics.ts
CHANGED
|
@@ -118,7 +118,7 @@ function reportObserveFailure(instrument: Instrument, thrown: unknown): void {
|
|
|
118
118
|
// `renderThrowable`, never `${thrown}`: the value is whatever the app's callback threw, and a
|
|
119
119
|
// `.message` read on it is the one that throws where there is nothing left to answer with.
|
|
120
120
|
cause: `the observe() callback of ${name} did not produce a value: ${renderThrowable(thrown)}; this instrument contributes no point until it does`,
|
|
121
|
-
fix: `
|
|
121
|
+
fix: `observe: () => pool?.size ?? 0 // in ${kind}('${name}', …): a total callback, a finite number even when the resource it reads is gone`,
|
|
122
122
|
meta: { metric: name },
|
|
123
123
|
});
|
|
124
124
|
logger.error(error.format(), { code: error.code, metric: name });
|
|
@@ -133,7 +133,7 @@ export function counter(name: string, options?: InstrumentOptions): Counter {
|
|
|
133
133
|
if (finite(name, value) < 0) {
|
|
134
134
|
throw new MetricValueInvalidError({
|
|
135
135
|
cause: `counter ${name} was decremented by ${value}; counters only go up`,
|
|
136
|
-
fix: `
|
|
136
|
+
fix: `gauge('${name}') // for a value that can fall — or pass add() a non-negative delta`,
|
|
137
137
|
meta: { metric: name, received: value },
|
|
138
138
|
});
|
|
139
139
|
}
|
package/src/otlp.ts
CHANGED
|
@@ -64,14 +64,14 @@ function assertHttpJson(signal: OtlpSignal, url: URL, env: OtlpEnv): void {
|
|
|
64
64
|
if (protocol !== '' && protocol !== 'http/json') {
|
|
65
65
|
throw new OtlpProtocolUnsupportedError({
|
|
66
66
|
cause: `${OTLP_PROTOCOL_KEY}="${protocol}" — this exporter speaks OTLP/HTTP JSON and nothing else`,
|
|
67
|
-
fix: `
|
|
67
|
+
fix: `export OTEL_EXPORTER_OTLP_PROTOCOL=http/json OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 # the collector's HTTP receiver; unsetting ${OTLP_PROTOCOL_KEY} works too`,
|
|
68
68
|
meta: { protocol, signal },
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
if (url.port === GRPC_PORT) {
|
|
72
72
|
throw new OtlpProtocolUnsupportedError({
|
|
73
73
|
cause: `${url.origin} is the collector's gRPC receiver (:${GRPC_PORT}); OTLP/HTTP JSON is served on :4318`,
|
|
74
|
-
fix: `
|
|
74
|
+
fix: `export OTEL_EXPORTER_OTLP_ENDPOINT=${renderFixShellArg(`${url.protocol}//${url.hostname}:4318`, '<the collector origin, on :4318>')}`,
|
|
75
75
|
meta: { endpoint: url.origin, signal },
|
|
76
76
|
});
|
|
77
77
|
}
|
|
@@ -85,14 +85,14 @@ function parseEndpoint(signal: OtlpSignal, raw: string, perSignal: boolean, env:
|
|
|
85
85
|
// Not echoed: an unparsable value may still be `user:password@…` with one character wrong.
|
|
86
86
|
throw new OtlpEndpointInvalidError({
|
|
87
87
|
cause: `the ${signal} OTLP endpoint is not a URL (${raw.length} characters, not echoed: it may carry a credential)`,
|
|
88
|
-
fix: `
|
|
88
|
+
fix: `export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318`,
|
|
89
89
|
meta: { signal },
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
93
93
|
throw new OtlpEndpointInvalidError({
|
|
94
94
|
cause: `"${otlpEndpointLabel(raw)}" is ${url.protocol}, and OTLP/HTTP needs http or https`,
|
|
95
|
-
fix: `
|
|
95
|
+
fix: `export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318`,
|
|
96
96
|
meta: { endpoint: otlpEndpointLabel(raw), signal },
|
|
97
97
|
});
|
|
98
98
|
}
|
|
@@ -161,7 +161,7 @@ export function otlpEndpoint(
|
|
|
161
161
|
if (resolved !== undefined) return resolved;
|
|
162
162
|
throw new OtlpEndpointInvalidError({
|
|
163
163
|
cause: `no OTLP endpoint: neither ${signalKey(signal, 'ENDPOINT')} nor ${OTLP_ENDPOINT_KEY} is set, and none was passed`,
|
|
164
|
-
fix: `
|
|
164
|
+
fix: `export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 # or skip the exporter when tryOtlpEndpoint('${signal}') is undefined`,
|
|
165
165
|
meta: { signal },
|
|
166
166
|
});
|
|
167
167
|
}
|
|
@@ -179,7 +179,7 @@ function decodeHeaderValue(variable: string, key: string, raw: string): string {
|
|
|
179
179
|
} catch {
|
|
180
180
|
throw new OtlpHeadersInvalidError({
|
|
181
181
|
cause: `${variable} carries a malformed percent-escape in the "${key}" value, so the header cannot be decoded`,
|
|
182
|
-
fix: `
|
|
182
|
+
fix: `bun -e 'console.log(encodeURIComponent(process.argv[1]))' <value> # prints <encoded>: set ${variable}=${key}=<encoded> — or drop the stray % from the "${key}" value if it was meant literally`,
|
|
183
183
|
meta: { header: key },
|
|
184
184
|
});
|
|
185
185
|
}
|
package/src/record-envelope.ts
CHANGED
|
@@ -117,6 +117,6 @@ function envelopeInvalid(where: string, what: string): UltimateError {
|
|
|
117
117
|
return new UltimateError({
|
|
118
118
|
code: 'X_CLIENT_RECORD_ENVELOPE_INVALID',
|
|
119
119
|
cause: `a response marked ${RECORDS_HEADER}: 1 carried a body where ${where} ${what}`,
|
|
120
|
-
fix: '
|
|
120
|
+
fix: 'encodeRecordEnvelope() // from @ultimat3/core, in the handler that set the header — or stop setting it',
|
|
121
121
|
});
|
|
122
122
|
}
|
package/src/roles.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Single responsibility: the runtime role table. One image, N processes; `ROLE` selects
|
|
2
2
|
// behaviour. Every role exposes /healthz + /readyz and drains on SIGTERM.
|
|
3
3
|
|
|
4
|
+
import { renderFixShellArg } from './error-render';
|
|
4
5
|
import { UltimateError } from './errors';
|
|
5
6
|
|
|
6
7
|
export const ROLES = ['web', 'sync', 'worker', 'scheduler', 'migrate', 'replicator'] as const;
|
|
@@ -58,7 +59,7 @@ export function resolveRole(options?: ResolveRoleOptions): Role {
|
|
|
58
59
|
throw new UltimateError({
|
|
59
60
|
code: 'X_ROLE_INVALID',
|
|
60
61
|
cause: `${key}="${raw}" is not one of ${ROLES.join(' | ')}`,
|
|
61
|
-
fix: `
|
|
62
|
+
fix: `export ${renderFixShellArg(key, '<the variable the cause names>')}=web # or one of: ${ROLES.join(', ')}`,
|
|
62
63
|
meta: { key, received: raw, allowed: ROLES },
|
|
63
64
|
});
|
|
64
65
|
}
|
package/src/sampler.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// collector melts". Separate from `telemetry.ts` because the decision is a policy an app replaces,
|
|
3
3
|
// while span construction is not.
|
|
4
4
|
|
|
5
|
+
import { renderFixShellArg } from './error-render';
|
|
5
6
|
import { logger } from './logger';
|
|
6
7
|
import type { SpanAttributes, SpanContext } from './telemetry';
|
|
7
8
|
|
|
@@ -111,7 +112,7 @@ function readRatio(raw: string | undefined, spelling: string): number {
|
|
|
111
112
|
// outage. Falling back to 1 keeps the traces — losing them silently is the worse failure.
|
|
112
113
|
logger.warn('X_TELEMETRY_SAMPLER_ARG_INVALID', {
|
|
113
114
|
cause: `${spelling}="${raw}" is not a ratio between 0 and 1; sampling every trace instead`,
|
|
114
|
-
fix: `
|
|
115
|
+
fix: `export ${renderFixShellArg(spelling, OTEL_SAMPLER_ARG_KEY)}=0.05 # a ratio between 0 and 1`,
|
|
115
116
|
});
|
|
116
117
|
return DEFAULT_SAMPLE_RATIO;
|
|
117
118
|
}
|
package/src/seal.ts
CHANGED
|
@@ -253,7 +253,7 @@ export async function openText(sealed: string, options: SealPurposeOptions): Pro
|
|
|
253
253
|
throw new UltimateError({
|
|
254
254
|
code: 'X_INVARIANT',
|
|
255
255
|
cause: `the value opened to ${bytes.length} byte(s) that are not UTF-8 text, so it was sealed from bytes and openText() cannot return it`,
|
|
256
|
-
fix: '
|
|
256
|
+
fix: 'await open(sealed, { purpose }) // not openText(): this value was sealed from a Uint8Array',
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
}
|
package/src/service.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function defineService<T>(name: string, factory: ServiceFactory<T>): Serv
|
|
|
31
31
|
throw new UltimateError({
|
|
32
32
|
code: 'X_SERVICE_DUPLICATE',
|
|
33
33
|
cause: `a service named "${name}" is already registered`,
|
|
34
|
-
fix: `
|
|
34
|
+
fix: `git grep -n defineService # two declare '${name}': rename one of them`,
|
|
35
35
|
meta: { name },
|
|
36
36
|
});
|
|
37
37
|
}
|