🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): return not-found for missing score config byId (#17679)
Max Deichmann0f70e58cc070
diff --git a/web/src/__tests__/server/scores-trpc.servertest.ts b/web/src/__tests__/server/scores-trpc.servertest.tsindex 6935285bba..ebbbef1e91 100644--- a/web/src/__tests__/server/scores-trpc.servertest.ts+++ b/web/src/__tests__/server/scores-trpc.servertest.ts@@ -1027,6 +1027,43 @@ describe("scores trpc", () => {});});+ describe("scoreConfigs.byId", () => {+ it("returns NOT_FOUND when the config is missing in the project", async () => {+ await expect(+ caller.scoreConfigs.byId({+ projectId,+ id: randomUUID(),+ }),+ ).rejects.toMatchObject({+ code: "NOT_FOUND",+ message: "No score config with this id in this project.",+ });+ });++ it("returns the config when it exists in the project", async () => {+ const config = await prisma.scoreConfig.create({+ data: {+ projectId,+ name: `byid-${randomUUID().slice(0, 8)}`,+ dataType: ScoreConfigDataType.NUMERIC,+ minValue: 0,+ maxValue: 1,+ },+ });++ await expect(+ caller.scoreConfigs.byId({+ projectId,+ id: config.id,+ }),+ ).resolves.toMatchObject({+ id: config.id,+ name: config.name,+ dataType: ScoreConfigDataType.NUMERIC,+ });+ });+ });+describe("scoreConfigs.appendCategory", () => {it("keeps both categories when two appends race", async () => {const config = await prisma.scoreConfig.create({diff --git a/web/src/server/api/routers/scoreConfigs.ts b/web/src/server/api/routers/scoreConfigs.tsindex c6166ee8b4..e1054a7839 100644--- a/web/src/server/api/routers/scoreConfigs.ts+++ b/web/src/server/api/routers/scoreConfigs.ts@@ -7,6 +7,7 @@ import {} from "@/src/server/api/trpc";import {filterAndValidateDbScoreConfigList,+ InternalServerError,InvalidRequestError,LangfuseNotFoundError,optionalPaginationZod,@@ -266,9 +267,17 @@ export const scoreConfigsRouter = createTRPCRouter({});if (!config) {- throw new Error("No score config with this id in this project.");+ throw new LangfuseNotFoundError(+ "No score config with this id in this project.",+ );}- return validateDbScoreConfig(config);+ const parsedConfig = validateDbScoreConfigSafe(config);+ if (!parsedConfig.success) {+ traceException(parsedConfig.error);+ throw new InternalServerError("Requested score config is corrupted");+ }++ return parsedConfig.data;}),});