Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/shaggy-parrots-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@inlang/cli": patch
---

Fix CLI commands not terminating by removing the shutdown wait on `fileQueueSettled`.

Also silence known non-actionable shutdown noise from background file queue processing when the DB is already closed.
6 changes: 1 addition & 5 deletions packages/cli/src/commands/machine/translate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Command } from "commander";
import { rpc } from "@inlang/rpc";
import {
getInlangProject,
settleLastUsedProjectFileQueue,
} from "../../utilities/getInlangProject.js";
import { getInlangProject } from "../../utilities/getInlangProject.js";
import { log, logError } from "../../utilities/log.js";
import {
saveProjectToDirectory,
Expand Down Expand Up @@ -41,7 +38,6 @@ export const translate = new Command()
logError(error);
exitCode = 1;
} finally {
await settleLastUsedProjectFileQueue();
process.exit(exitCode);
}
});
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/commands/validate/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Command } from "commander";
import {
getInlangProject,
settleLastUsedProjectFileQueue,
} from "../../utilities/getInlangProject.js";
import { getInlangProject } from "../../utilities/getInlangProject.js";
import { log } from "../../utilities/log.js";
import { projectOption } from "../../utilities/globalFlags.js";

Expand Down Expand Up @@ -32,7 +29,6 @@ export async function validateCommandAction(args: { project: string }) {
log.error(error);
exitCode = 1;
} finally {
await settleLastUsedProjectFileQueue();
process.exit(exitCode);
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { machine } from "./commands/machine/index.js";
import { plugin } from "./commands/plugin/index.js";
import { version } from "../package.json";
import { initErrorMonitoring } from "./services/error-monitoring/implementation.js";
import { silenceKnownShutdownNoise } from "./services/error-monitoring/silenceKnownShutdownNoise.js";
import { validate } from "./commands/validate/index.js";
import { capture } from "./telemetry/capture.js";
import { lastUsedProject } from "./utilities/getInlangProject.js";
Expand All @@ -11,6 +12,7 @@ import { lint } from "./commands/lint/index.js";
// --------------- INIT ---------------

initErrorMonitoring();
silenceKnownShutdownNoise();
// checks whether the gitOrigin corresponds to the pattern

// beautiful logging
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const FILE_QUEUE_CONTEXT_PATTERN = /(file queue|Error processing file queue entry)/i;
const DB_CLOSED_PATTERN = /(DB has been closed|driver has already been destroyed)/i;

function shouldSilenceConsoleError(args: unknown[]): boolean {
if (args.length === 0) {
return false;
}

const text = args
.map((arg) => {
if (arg instanceof Error) {
return `${arg.name}: ${arg.message}`;
}
return String(arg);
})
.join(" ");

return FILE_QUEUE_CONTEXT_PATTERN.test(text) && DB_CLOSED_PATTERN.test(text);
}

export function silenceKnownShutdownNoise(): void {
const originalConsoleError = console.error.bind(console);

console.error = (...args: unknown[]) => {
if (shouldSilenceConsoleError(args)) {
return;
}

originalConsoleError(...args);
};
}
12 changes: 0 additions & 12 deletions packages/cli/src/utilities/getInlangProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "node:fs";
import { loadProjectFromDirectory, type InlangProject } from "@inlang/sdk";
import { fileQueueSettled } from "@inlang/sdk/lix";
import { resolve } from "node:path";

/**
Expand Down Expand Up @@ -31,14 +30,3 @@ export async function getInlangProject(args: {
process.exit(1);
}
}

export async function settleLastUsedProjectFileQueue(): Promise<void> {
if (!lastUsedProject) {
return;
}
try {
await fileQueueSettled({ lix: lastUsedProject.lix });
} catch {
// Best-effort: ignore queue settle failures during shutdown.
}
}