refactor: dedupe tlon monitor error formatting

This commit is contained in:
Peter Steinberger
2026-04-06 22:32:27 +01:00
parent daa0a755df
commit d56e343d30
4 changed files with 7 additions and 15 deletions

View File

@@ -1,10 +1,6 @@
import type { RuntimeEnv } from "../../api.js";
import type { Foreigns } from "../urbit/foreigns.js";
import { asRecord, formatChangesDate } from "./utils.js";
function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
import { asRecord, formatChangesDate, formatErrorMessage } from "./utils.js";
export async function fetchGroupChanges(
api: { scry: (path: string) => Promise<unknown> },

View File

@@ -1,9 +1,5 @@
import type { RuntimeEnv } from "../../api.js";
import { asRecord, extractMessageText } from "./utils.js";
function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
import { asRecord, extractMessageText, formatErrorMessage } from "./utils.js";
/**
* Format a number as @ud (with dots every 3 digits from the right)

View File

@@ -28,7 +28,7 @@ import {
mergeUniqueStrings,
shouldMigrateTlonSetting,
} from "./settings-helpers.js";
import { asRecord } from "./utils.js";
import { asRecord, formatErrorMessage } from "./utils.js";
import {
extractMessageText,
formatModelName,
@@ -56,10 +56,6 @@ function readNumber(record: Record<string, unknown> | null, key: string): number
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
}
function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
export async function monitorTlonProvider(opts: MonitorTlonOpts = {}): Promise<void> {
const core = getTlonRuntime();
const cfg = core.config.loadConfig();

View File

@@ -185,6 +185,10 @@ export function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}
export function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function readString(record: Record<string, unknown>, key: string): string | undefined {
const value = record[key];
return typeof value === "string" ? value : undefined;