fix: assorted fixes

This commit is contained in:
zk
2026-06-20 13:11:42 +00:00
parent 78e23ab7cd
commit 75bf78ad38
4 changed files with 33 additions and 4 deletions
@@ -10,6 +10,7 @@ import {
type ChartDocument,
CreateSongID,
type GameGroupFromGame,
GameToGameGroup,
type SongDocument,
} from "tachi-common";
@@ -42,7 +43,13 @@ export async function DeorphanBmsIfInOrphanChartPg(
log.info(`Song ${songDoc.title} was unorphaned forcefully (Postgres).`);
const songLegacyId = await GetNextBmsPmsSongLegacyId("bms");
const gameGroup = GameToGameGroup(game);
if (gameGroup !== "bms" && gameGroup !== "pms") {
throw new Error(`DeorphanBmsIfInOrphanChartPg called with non-BMS/PMS game: ${game}`);
}
const songLegacyId = await GetNextBmsPmsSongLegacyId(gameGroup);
const songNewID = CreateSongID();
songDoc.id = songNewID;
@@ -60,7 +67,7 @@ export async function DeorphanBmsIfInOrphanChartPg(
.values({
id: songNewID,
legacy_id: songLegacyId,
game_group: "bms",
game_group: gameGroup,
title: songDoc.title,
artist: songDoc.artist,
search_terms: songDoc.searchTerms,
@@ -11,6 +11,8 @@ import {
import type { DryScore } from "../common/types";
import { InvalidScoreFailure } from "../common/converter-failures";
export const LEGACY_CHART_ID_LENGTH = 40;
export function assertLegacyChartIDForScoreID(legacyChartID: string): void {
@@ -46,8 +48,15 @@ export function CreateScoreID(
for (const m of Object.keys(gameConfig.providedMetrics)) {
const metric = m as keyof MongoProvidedMetrics[V3Game];
const value = dryScore.scoreData[metric];
elements[metric] = dryScore.scoreData[metric];
if (value === undefined) {
throw new InvalidScoreFailure(
`Required metric '${metric}' is undefined in score data for game ${game}. The score may predate this metric being added.`,
);
}
elements[metric] = value;
}
// Also include optional metrics in the checksum if they should be
@@ -153,6 +153,19 @@ export async function ImportIterableDatapoint<D, C>(
// if this isn't a converterFailure, it's just a general error.
// Some sort of internal issue?
if (!IsConverterFailure(err)) {
// rg-stats ThrowIf assertions produce plain Errors prefixed with
// "Invalid input," - these represent bad user data, not server bugs.
// This is a pretty dirty fix for this, but whatever.
if (err instanceof Error && err.message.startsWith("Invalid input,")) {
log.info({ err }, `rg-stats input assertion failed, treating as InvalidDatapoint.`);
return {
success: false,
type: "InvalidDatapoint",
message: err.message,
content: {},
};
}
log.error(
{
err,
+1 -1
View File
@@ -26,7 +26,7 @@ export async function GetKaiAuthGuaranteed(
const authDoc = await GetKaiAuth(userID, service);
if (!authDoc) {
log.error(`No authentication was stored for ${service}.`);
log.warn(`No authentication was stored for ${service}.`);
throw new ScoreImportFatalError(401, `No authentication was stored for ${service}.`);
}