Skip to content

Commit

Permalink
feat: rename error function to logError (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal authored Aug 9, 2024
1 parent 9a7c7ac commit 36f9cc2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ setOutput("output-name", "some value");

### Logging Errors

Errors can be logged using the `error` function, which can log errors of any type. This is especially useful for logging caught errors:
Errors can be logged using the `logError` function, which can log errors of any type. This is especially useful for logging caught errors:

```ts
try {
// Do something
} catch (err) {
error(err);
logError(err);
}
```

Expand Down
12 changes: 6 additions & 6 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest } from "@jest/globals";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { error, getInput, setOutput } from "./index.js";
import { getInput, logError, setOutput } from "./index.js";

describe("retrieve GitHub Actions inputs", () => {
it("should retrieve a GitHub Actions input", () => {
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("set GitHub Actions outputs", () => {
});
});

describe("log errors on GitHub Actions", () => {
describe("log errors in GitHub Actions", () => {
let stdoutData: string;
beforeAll(() => {
jest
Expand All @@ -52,15 +52,15 @@ describe("log errors on GitHub Actions", () => {
});
});

it("should log an error message on GitHub Actions", () => {
it("should log an error message in GitHub Actions", () => {
stdoutData = "";
error("some error message");
logError("some error message");
expect(stdoutData).toBe(`::error::some error message${os.EOL}`);
});

it("should log an error object on GitHub Actions", () => {
it("should log an error object in GitHub Actions", () => {
stdoutData = "";
error(new Error("some error object"));
logError(new Error("some error object"));
expect(stdoutData).toBe(`::error::some error object${os.EOL}`);
});
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export function setOutput(name: string, value: string): void {
}

/**
* Logs an error message on GitHub Actions.
* Logs an error message in GitHub Actions.
*
* @param err - The error, which can be of any type.
*/
export function error(err: unknown): void {
export function logError(err: unknown): void {
const message = err instanceof Error ? err.message : String(err);
process.stdout.write(`::error::${message}${os.EOL}`);
}

0 comments on commit 36f9cc2

Please sign in to comment.