The best way to control Claude Code, Codex and more from any computer or phone
fix(server): logs print causes instead of [Object] (#16642)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com>
Alex Southwell committed
Oct 19, 2026 at 06:29 UTC
a4cd9216dd6ab144d305294e1c87fb4c68c0afe2
2 files changed
+107
-2
apps/server/src/serverLogger.test.ts
+66
@@ -1,12 +1,16 @@
1
import * as NodePath from "@effect/platform-node/NodePath";
2
import { assert, describe, it } from "@effect/vitest";
3
import * as NodeOS from "node:os";
4
+import * as NodeUtil from "node:util";
5
+
6
import { ExternalLauncherBrowserSpawnError } from "@t3tools/contracts";
7
import * as Cause from "effect/Cause";
8
import * as ConfigProvider from "effect/ConfigProvider";
9
+import * as Console from "effect/Console";
10
import * as Effect from "effect/Effect";
11
import * as Exit from "effect/Exit";
12
import * as Layer from "effect/Layer";
13
+import * as Redactable from "effect/Redactable";
14
import * as Path from "effect/Path";
15
import * as Tracer from "effect/Tracer";
16
import * as HttpClient from "effect/http/HttpClient";
@@ -147,6 +151,25 @@ const logInSpanThrough = (
151
return { requests, spans };
152
});
153
154
+/** Logs one warning through the server logger and returns what its console printed. */
155
+const printThroughConsole = (fields: object) =>
156
+ Effect.gen(function* () {
157
+ const printed: Array<string> = [];
158
+ const testConsole = {
159
+ ...globalThis.console,
160
+ log: (...args: ReadonlyArray<unknown>) => {
161
+ printed.push(NodeUtil.format(...args));
162
+ },
163
+ } satisfies Console.Console;
164
+ yield* Effect.logWarning("pull request watch check failed", fields).pipe(
165
+ Effect.provide(
166
+ ServerLogger.layer.pipe(Layer.provide(layerConfig({})), Layer.provide(layerCollector([]))),
167
+ ),
168
+ Effect.provideService(Console.Console, testConsole),
169
+ );
170
+ return printed.join("\n");
171
+ });
172
+
173
describe("ServerLoggerLive", () => {
174
it.effect("exports log records to the configured logs endpoint", () =>
175
Effect.gen(function* () {
@@ -241,6 +264,49 @@ describe("ServerLoggerLive", () => {
264
}),
265
);
266
267
+ it.effect("prints a cause passed as a log field instead of collapsing it", () =>
268
+ Effect.gen(function* () {
269
+ const output = yield* printThroughConsole({
270
+ threadId: "thread-1",
271
+ cause: Cause.fail(new Error("gh: HTTP 502 from api.github.com")),
272
+ });
273
+
274
+ assert.include(output, "threadId: 'thread-1'");
275
+ assert.include(output, "gh: HTTP 502 from api.github.com");
276
+ assert.notInclude(output, "[Object]");
277
+ }),
278
+ );
279
+
280
+ it.effect("leaves getters uncalled while printing a cause field", () =>
281
+ Effect.gen(function* () {
282
+ const output = yield* printThroughConsole({
283
+ cause: Cause.fail(new Error("upstream refused")),
284
+ get detail(): string {
285
+ throw new Error("getter must not run");
286
+ },
287
+ });
288
+
289
+ assert.include(output, "upstream refused");
290
+ assert.notInclude(output, "getter must not run");
291
+ }),
292
+ );
293
+
294
+ it.effect("leaves a message with its own redaction hook to that hook", () =>
295
+ Effect.gen(function* () {
296
+ const output = yield* printThroughConsole({
297
+ token: "secret-token-value",
298
+ cause: Cause.fail(new Error("upstream refused")),
299
+ [Redactable.symbolRedactable](this: { readonly cause: unknown }) {
300
+ return { token: "<redacted>", cause: Cause.isCause(this.cause) ? "cause" : "missing" };
301
+ },
302
+ });
303
+
304
+ assert.include(output, "token: '<redacted>'");
305
+ assert.include(output, "cause: 'cause'");
306
+ assert.notInclude(output, "secret-token-value");
307
+ }),
308
+ );
309
+
310
describe("startup pairing URL", () => {
311
const pairingToken = "PAIRTOKEN7Q4K9";
312
const pairingUrl = `http://localhost:3773/pair#token=${pairingToken}`;
apps/server/src/serverLogger.ts
+41
-2
@@ -1,14 +1,53 @@
1
import * as HostProcess from "@t3tools/shared/HostProcess";
2
import * as SharedObservability from "@t3tools/shared/observability";
3
+import * as Cause from "effect/Cause";
4
import * as Effect from "effect/Effect";
5
import * as Layer from "effect/Layer";
6
import * as Logger from "effect/Logger";
7
+import * as Redactable from "effect/Redactable";
8
import * as References from "effect/References";
9
import * as OtlpExporter from "effect/observability/OtlpExporter";
10
import * as OtlpLogger from "effect/observability/OtlpLogger";
11
12
import * as ServerConfig from "./config.ts";
13
14
+/**
15
+ * `Logger.consolePretty` prints message objects with `util.inspect`, which
16
+ * collapses a `Cause` passed as a field (`{ cause }`) to
17
+ * `{ failures: [ [Object] ] }`. Render those fields with `Cause.pretty`, the
18
+ * same text a `Cause` passed as its own log argument already gets.
19
+ */
20
+const consolePretty = (): Logger.Logger<unknown, void> => {
21
+ const pretty = Logger.consolePretty();
22
+ return Logger.make((options) =>
23
+ pretty.log({
24
+ ...options,
25
+ message: Array.isArray(options.message)
26
+ ? options.message.map(prettyCauseFields)
27
+ : prettyCauseFields(options.message),
28
+ }),
29
+ );
30
+};
31
+
32
+function prettyCauseFields(value: unknown): unknown {
33
+ if (typeof value !== "object" || value === null) return value;
34
+ const prototype: unknown = Object.getPrototypeOf(value);
35
+ if (prototype !== Object.prototype && prototype !== null) return value;
36
+ // A message with its own redaction hook already decides how it prints.
37
+ if (Redactable.isRedactable(value)) return value;
38
+ // Copy descriptors rather than entries so getters are never invoked and
39
+ // symbol keys survive the copy.
40
+ const descriptors = Object.getOwnPropertyDescriptors(value);
41
+ let changed = false;
42
+ for (const descriptor of Object.values(descriptors)) {
43
+ if ("value" in descriptor && Cause.isCause(descriptor.value)) {
44
+ descriptor.value = Cause.pretty(descriptor.value);
45
+ changed = true;
46
+ }
47
+ }
48
+ return changed ? Object.create(prototype, descriptors) : value;
49
+}
50
+
51
export const layer = Effect.gen(function* () {
52
const config = yield* ServerConfig.ServerConfig;
53
const hostName = yield* HostProcess.Hostname;
@@ -34,8 +73,8 @@ export const layer = Effect.gen(function* () {
73
// superset: keeping both would export every in-span message twice.
74
const layerLogger = Logger.layer(
75
otlpLogger === undefined
37
- ? [Logger.consolePretty(), Logger.tracerLogger]
38
- : [Logger.consolePretty(), otlpLogger],
76
+ ? [consolePretty(), Logger.tracerLogger]
77
+ : [consolePretty(), otlpLogger],
78
{ mergeWithExisting: false },
79
).pipe(
80
Layer.provide(OtlpExporter.layerFlusher),