Skip to content

Commit 348b253

Browse files
authored
chore(statusline): replace unreachable from errorutil (#602)
* chore(statusline): use unreachable * chore: replace errorutil
1 parent bad49f6 commit 348b253

5 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎bun.lock‎

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
},
6565
"devDependencies": {
6666
"@antfu/utils": "^9.2.0",
67-
"@core/errorutil": "npm:@jsr/core__errorutil@^1.2.1",
6867
"@hono/mcp": "^0.1.0",
6968
"@hono/node-server": "^1.19.0",
7069
"@mizchi/lsmcp": "^0.10.0",

‎src/_utils.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { createFixture } from 'fs-fixture';
77
import pc from 'picocolors';
88
import stringWidth from 'string-width';
99

10+
export function unreachable(value: never): never {
11+
throw new Error(`Unreachable code reached with value: ${value as any}`);
12+
}
13+
1014
/**
1115
* Table row data type supporting strings, numbers, and formatted cell objects
1216
*/
@@ -419,6 +423,14 @@ export async function getFileModifiedTime(filePath: string): Promise<number> {
419423
}
420424

421425
if (import.meta.vitest != null) {
426+
describe('unreachable', () => {
427+
it('should throw an error when called', () => {
428+
expect(() => unreachable('test' as never)).toThrow(
429+
'Unreachable code reached with value: test',
430+
);
431+
});
432+
});
433+
422434
describe('ResponsiveTable', () => {
423435
describe('compact mode behavior', () => {
424436
it('should activate compact mode when terminal width is below threshold', () => {

‎src/commands/statusline.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DEFAULT_CONTEXT_USAGE_THRESHOLDS, DEFAULT_REFRESH_INTERVAL_SECONDS } fr
1414
import { calculateBurnRate } from '../_session-blocks.ts';
1515
import { sharedArgs } from '../_shared-args.ts';
1616
import { statuslineHookJsonSchema } from '../_types.ts';
17-
import { formatCurrency, getFileModifiedTime } from '../_utils.ts';
17+
import { formatCurrency, getFileModifiedTime, unreachable } from '../_utils.ts';
1818
import { calculateTotals } from '../calculate-cost.ts';
1919
import { calculateContextTokens, loadDailyUsageData, loadSessionBlockData, loadSessionUsageById } from '../data-loader.ts';
2020
import { log, logger } from '../logger.ts';
@@ -293,7 +293,7 @@ export const statuslineCommand = define({
293293
const cost = await getCcusageCost();
294294
return { sessionCost: cost };
295295
}
296-
costSource satisfies never; // Exhaustiveness check
296+
unreachable(costSource);
297297
return {}; // This line should never be reached
298298
})();
299299

‎src/data-loader.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { readFile } from 'node:fs/promises';
2424
import path from 'node:path';
2525
import process from 'node:process';
2626
import { toArray } from '@antfu/utils';
27-
import { unreachable } from '@core/errorutil';
2827
import { Result } from '@praha/byethrow';
2928
import { groupBy, uniq } from 'es-toolkit'; // TODO: after node20 is deprecated, switch to native Object.groupBy
3029
import { sort } from 'fast-sort';
@@ -60,6 +59,7 @@ import {
6059
versionSchema,
6160
weeklyDateSchema,
6261
} from './_types.ts';
62+
import { unreachable } from './_utils.ts';
6363
import { logger } from './logger.ts';
6464
import { PricingFetcher } from './pricing-fetcher.ts';
6565

0 commit comments

Comments
 (0)