From ab8b6cbb694159f417d5d7363526e7288b1c3f66 Mon Sep 17 00:00:00 2001 From: Ranjani Veena Belavadi Date: Fri, 10 Jul 2026 14:14:07 -0700 Subject: [PATCH 1/2] Add unit test coverage for extractErrorMessage --- frontend/src/app/common/util/error.spec.ts | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 frontend/src/app/common/util/error.spec.ts diff --git a/frontend/src/app/common/util/error.spec.ts b/frontend/src/app/common/util/error.spec.ts new file mode 100644 index 00000000000..0c4710dd0aa --- /dev/null +++ b/frontend/src/app/common/util/error.spec.ts @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { extractErrorMessage } from "./error"; + +describe("extractErrorMessage", () => { + it("should return the message from an Error instance", () => { + const testError = new Error("error instance"); + const result = extractErrorMessage(testError); + expect(result).toBe(testError.message); + }); + + it("should return the error string when error is a plain string", () => { + const testError = {error : "boom"}; + const result = extractErrorMessage(testError); + expect(result).toBe(testError.error); + }); + + it("should return the nested message when error is an object with a message", () => { + const testError = { error: { message: "nested" } }; + const result = extractErrorMessage(testError); + expect(result).toBe(testError.error.message); + }); + + it("should return the fallback message for when error is null", () => { + const testError = null; + const result = extractErrorMessage(testError); + expect(result).toBe("An unknown error occurred."); + }); + + it("should return the fallback message when error is a number", () => { + const testError = 123; + const result = extractErrorMessage(testError); + expect(result).toBe("An unknown error occurred."); + }); + + it("should return the fallback message when error is an empty object", () => { + const testError = {}; + const result = extractErrorMessage(testError); + expect(result).toBe("An unknown error occurred."); + }); + + it("should return the fallback message when error key value is neither a string nor an object with a message", () => { + const testError = {error : 123}; + const result = extractErrorMessage(testError); + expect(result).toBe("An unknown error occurred."); + }); +}); + + + From ff1a1c5e5b1578d38aaf2efbc2b2980735a5caf5 Mon Sep 17 00:00:00 2001 From: Ranjani Veena Belavadi Date: Fri, 10 Jul 2026 14:33:04 -0700 Subject: [PATCH 2/2] Fix formatting per Prettier/ESLint --- frontend/src/app/common/util/error.spec.ts | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/common/util/error.spec.ts b/frontend/src/app/common/util/error.spec.ts index 0c4710dd0aa..b3ec09b24ea 100644 --- a/frontend/src/app/common/util/error.spec.ts +++ b/frontend/src/app/common/util/error.spec.ts @@ -20,19 +20,19 @@ import { extractErrorMessage } from "./error"; describe("extractErrorMessage", () => { - it("should return the message from an Error instance", () => { - const testError = new Error("error instance"); - const result = extractErrorMessage(testError); - expect(result).toBe(testError.message); - }); + it("should return the message from an Error instance", () => { + const testError = new Error("error instance"); + const result = extractErrorMessage(testError); + expect(result).toBe(testError.message); + }); - it("should return the error string when error is a plain string", () => { - const testError = {error : "boom"}; - const result = extractErrorMessage(testError); - expect(result).toBe(testError.error); - }); + it("should return the error string when error is a plain string", () => { + const testError = { error: "boom" }; + const result = extractErrorMessage(testError); + expect(result).toBe(testError.error); + }); - it("should return the nested message when error is an object with a message", () => { + it("should return the nested message when error is an object with a message", () => { const testError = { error: { message: "nested" } }; const result = extractErrorMessage(testError); expect(result).toBe(testError.error.message); @@ -57,11 +57,8 @@ describe("extractErrorMessage", () => { }); it("should return the fallback message when error key value is neither a string nor an object with a message", () => { - const testError = {error : 123}; + const testError = { error: 123 }; const result = extractErrorMessage(testError); expect(result).toBe("An unknown error occurred."); }); }); - - -