Copilot commented on code in PR #6321: URL: https://github.com/apache/texera/pull/6321#discussion_r3562246021
########## frontend/src/app/common/util/error.spec.ts: ########## @@ -0,0 +1,64 @@ +/** + * 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); + }); Review Comment: `extractErrorMessage` currently throws for inputs like `{ error: null }` because `typeof null === "object"` and the implementation uses `'message' in backendErr` without a null check. Since this helper is used in UI error reporting, it should never throw; please add a regression test for `{ error: null }` (and ideally `{ error: { message: 123 } }`) and update the implementation to guard `backendErr !== null` (and ensure `message` is a string) before returning it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
